function getFullTermLabel($dtTerms, $term, $domain, $withVocab = false) { $fi = $dtTerms['fieldNamesToIndex']; $parent_id = $term[$fi['trm_ParentTermID']]; $parent_label = ''; if ($parent_id != null && $parent_id > 0) { $term_parent = @$dtTerms['termsByDomainLookup'][$domain][$parent_id]; if ($term_parent) { if (!$withVocab) { $parent_id = $term_parent[$fi['trm_ParentTermID']]; if (!($parent_id > 0)) { return $term[$fi['trm_Label']]; } } $parent_label = getFullTermLabel($dtTerms, $term_parent, $domain, $withVocab); if ($parent_label) { $parent_label = $parent_label . '.'; } } } return $parent_label . $term[$fi['trm_Label']]; }
private function getDetailForSmarty($dtKey, $dtValue, $recTypeID, $recID) { $dtNames = $this->dtStructs['names']; $rtNames = $this->rtStructs['names']; $dty_fi = $this->dtStructs['typedefs']['fieldNamesToIndex']; $rt_structure = null; $issingle = true; if ($dtKey < 1 || $dtNames[$dtKey]) { if ($dtKey < 1) { $dt_label = "Relationship"; $dtname = "Relationship"; $issingle = false; $dtDef = "dummy"; } else { $rt_structure = $this->rtStructs['typedefs'][$recTypeID]['dtFields']; $rst_fi = $this->rtStructs['typedefs']['dtFieldNamesToIndex']; $dtlabel_index = $rst_fi['rst_DisplayName']; $dtmaxval_index = $rst_fi['rst_MaxValues']; if (array_key_exists($dtKey, $rt_structure)) { $dt_label = $rt_structure[$dtKey][$dtlabel_index]; //$dtname = getVariableNameForSmarty($dt_label); } $dtname = "f" . $dtKey; // TODO: what is this: Artem 2013-12-09 getVariableNameForSmarty($dtNames[$dtKey]); $dtDef = @$this->dtStructs['typedefs'][$dtKey]['commonFields']; } if (is_array($dtValue)) { //complex type - need more analize $res = null; if ($dtDef) { if ($dtKey < 1) { $detailType = "relmarker"; } else { $detailType = $dtDef[$dty_fi['dty_Type']]; //detect single or repeatable - if repeatable add as array for enum and pointers $dt_maxvalues = @$rt_structure[$dtKey][$dtmaxval_index]; if ($dt_maxvalues) { $issingle = is_numeric($dt_maxvalues) && intval($dt_maxvalues) === 1; } else { $issingle = false; } $issingle = false; } switch ($detailType) { case 'enum': case 'relationtype': $domain = $detailType == "enum" ? "enum" : "relation"; $fi = $this->dtTerms['fieldNamesToIndex']; $res_id = ""; $res_cid = ""; $res_code = ""; $res_label = ""; $res_label_full = ''; $res = array(); foreach ($dtValue as $key => $value) { if (array_key_exists($value, $this->dtTerms['termsByDomainLookup'][$domain])) { $term = $this->dtTerms['termsByDomainLookup'][$domain][$value]; //IJ wants to show terms for all parents $term_full = getFullTermLabel($this->dtTerms, $term, $domain, false); $res_id = $this->_add_term_val($res_id, $value); $res_cid = $this->_add_term_val($res_cid, $term[$fi['trm_ConceptID']]); $res_code = $this->_add_term_val($res_code, $term[$fi['trm_Code']]); $res_label_full = $this->_add_term_val($res_label_full, $term_full); $res_label = $this->_add_term_val($res_label, $term[$fi['trm_Label']]); //NOTE id and label are for backward array_push($res, array("id" => $value, "internalid" => $value, "code" => $term[$fi['trm_Code']], "label" => $term[$fi['trm_Label']], "term" => $term_full, "conceptid" => $term[$fi['trm_ConceptID']])); } } $res_united = array("id" => $res_id, "internalid" => $res_id, "code" => $res_code, "term" => $res_label_full, "label" => $res_label, "conceptid" => $res_cid); if (count($res) > 0) { if ($issingle) { $res = array($dtname => $res_united); } else { $res = array($dtname => $res[0], $dtname . "s" => $res); } } break; case 'date': $res = ""; $origvalues = array(); foreach ($dtValue as $key => $value) { if (strlen($res) > 0) { $res = $res . ", "; } $res = $res . temporalToHumanReadableString($value); array_push($origvalues, temporalToHumanReadableString($value)); } if (strlen($res) == 0) { //no valid terms $res = null; } else { $res = array($dtname => $res, $dtname . "_originalvalue" => $origvalues); } break; case 'file': //get url for file download //if image - special case $res = ""; $origvalues = array(); foreach ($dtValue as $key => $value) { if (strlen($res) > 0) { $res = $res . ", "; } $res = $res . $value['file']['URL']; //original value keeps the whole 'file' array array_push($origvalues, $value['file']); } if (strlen($res) == 0) { $res = null; } else { $res = array($dtname => $res, $dtname . "_originalvalue" => $origvalues); //array_merge($arres, array($dtname=>$res)); } break; case 'geo': $res = ""; $arres = array(); foreach ($dtValue as $key => $value) { //original value keeps whole geo array $dtname2 = $dtname . "_originalvalue"; $value['geo']['recid'] = $recID; $arres = array_merge($arres, array($dtname2 => $value['geo'])); $res = $value['geo']['wkt']; break; //only one geo location at the moment } if (strlen($res) == 0) { $res = null; } else { $res = array_merge($arres, array($dtname => $res)); //$res = array( $dtname=>$res ); } break; case 'separator': case 'calculated': case 'fieldsetmarker': break; case 'relmarker': // NOT USED break; case 'resource': // link to another record type $res = array(); if (count($dtValue) > 0) { //error_log(print_r($dtValue,true)); foreach ($dtValue as $key => $value) { $recordID = $value['id']; array_push($res, $recordID); } if ($issingle) { $res = array($dtname => $res[0]); } else { $res = array($dtname => $res[0], $dtname . "s" => $res); } //error_log(print_r($res,true)); } break; /* OLD WAY //@todo - parsing will depend on depth level // if there are not mentions about this record type in template (based on obtained array of variables) // we will create href link to this record // otherwise - we have to obtain this record (by ID) and add subarray $res = array(); $rectypeID = null; $prevID = null; $order_sub = 0; foreach ($dtValue as $key => $value){ if($recursion_depth<$max_allowed_depth && (array_key_exists('id',$value) || array_key_exists('RelatedRecID',$value))) { //this is record ID if(array_key_exists('RelatedRecID',$value)){ $recordID = $value['RelatedRecID']['rec_ID']; }else{ $recordID = $value['id']; } //error_log('relrecid '.$recordID); $res0 = null; //get full record info if(@$this->loaded_recs[$recordID]){ //already loaded $res0 = $this->loaded_recs[$recordID]; $rectypeID = $res0['recTypeID']; //error_log('already loaded '.print_r($res0,true)); }else{ $record = loadRecord($recordID, false, true); //from search/getSearchResults.php if(true){ //load linked records dynamically $res0 = getRecordForSmarty($record, $recursion_depth+1, $order_sub); //@todo - need to $order_sub++; //error_log('load '.print_r($res0,true)); } if($rectypeID==null && $res0 && @$res0['recRecTypeID']){ $rectypeID = $res0['recRecTypeID']; } } if($res0){ //unset rel fields to avoid conflict if this records was already loaded if(@$res0["recRelationType"] ) unset($res0["recRelationType"]); if(@$res0["recRelationNotes"] ) unset($res0["recRelationNotes"]); if(@$res0["recRelationStartDate"] ) unset($res0["recRelationStartDate"]); if(@$res0["recRelationEndDate"] ) unset($res0["recRelationEndDate"]); //add relationship specific variables if(array_key_exists('RelatedRecID',$value) && array_key_exists('RelTerm',$value)){ $res0["recRelationType"] = $value['RelTerm']; if(array_key_exists('Notes', $value)){ $res0["recRelationNotes"] = $value['Notes']; } if(array_key_exists('StartDate', $value)){ $res0["recRelationStartDate"] = temporalToHumanReadableString($value['StartDate']); } if(array_key_exists('EndDate', $value)){ $res0["recRelationEndDate"] = temporalToHumanReadableString($value['EndDate']); } } $this->loaded_recs[$recordID] = $res0; //$res0["recOrder"] = count($res); array_push($res, $res0); } } }//for each repeated value if( count($res)>0 && array_key_exists($rectypeID, $rtNames)) { //DEBUG2 if($recID==5434) error_log('recid '.$recID.' '.print_r($res, true)); if(@$dtname){ if($issingle){ $res = array( $dtname =>$res[0] ); }else{ $res = array( $dtname =>$res[0], $dtname."s" =>$res ); } } }else{ $res = null; } break; */ /* OLD WAY //@todo - parsing will depend on depth level // if there are not mentions about this record type in template (based on obtained array of variables) // we will create href link to this record // otherwise - we have to obtain this record (by ID) and add subarray $res = array(); $rectypeID = null; $prevID = null; $order_sub = 0; foreach ($dtValue as $key => $value){ if($recursion_depth<$max_allowed_depth && (array_key_exists('id',$value) || array_key_exists('RelatedRecID',$value))) { //this is record ID if(array_key_exists('RelatedRecID',$value)){ $recordID = $value['RelatedRecID']['rec_ID']; }else{ $recordID = $value['id']; } //error_log('relrecid '.$recordID); $res0 = null; //get full record info if(@$this->loaded_recs[$recordID]){ //already loaded $res0 = $this->loaded_recs[$recordID]; $rectypeID = $res0['recTypeID']; //error_log('already loaded '.print_r($res0,true)); }else{ $record = loadRecord($recordID, false, true); //from search/getSearchResults.php if(true){ //load linked records dynamically $res0 = getRecordForSmarty($record, $recursion_depth+1, $order_sub); //@todo - need to $order_sub++; //error_log('load '.print_r($res0,true)); } if($rectypeID==null && $res0 && @$res0['recRecTypeID']){ $rectypeID = $res0['recRecTypeID']; } } if($res0){ //unset rel fields to avoid conflict if this records was already loaded if(@$res0["recRelationType"] ) unset($res0["recRelationType"]); if(@$res0["recRelationNotes"] ) unset($res0["recRelationNotes"]); if(@$res0["recRelationStartDate"] ) unset($res0["recRelationStartDate"]); if(@$res0["recRelationEndDate"] ) unset($res0["recRelationEndDate"]); //add relationship specific variables if(array_key_exists('RelatedRecID',$value) && array_key_exists('RelTerm',$value)){ $res0["recRelationType"] = $value['RelTerm']; if(array_key_exists('Notes', $value)){ $res0["recRelationNotes"] = $value['Notes']; } if(array_key_exists('StartDate', $value)){ $res0["recRelationStartDate"] = temporalToHumanReadableString($value['StartDate']); } if(array_key_exists('EndDate', $value)){ $res0["recRelationEndDate"] = temporalToHumanReadableString($value['EndDate']); } } $this->loaded_recs[$recordID] = $res0; //$res0["recOrder"] = count($res); array_push($res, $res0); } } }//for each repeated value if( count($res)>0 && array_key_exists($rectypeID, $rtNames)) { //DEBUG2 if($recID==5434) error_log('recid '.$recID.' '.print_r($res, true)); if(@$dtname){ if($issingle){ $res = array( $dtname =>$res[0] ); }else{ $res = array( $dtname =>$res[0], $dtname."s" =>$res ); } } }else{ $res = null; } break; */ default: // repeated basic detail types $res = ""; $origvalues = array(); foreach ($dtValue as $key => $value) { if (strlen($res) > 0) { $res = $res . ", "; } $res = $res . $value; array_push($origvalues, $value); } if (strlen($res) == 0) { //no valid terms $res = null; } else { $res = array($dtname => $res, $dtname . "_originalvalue" => $origvalues); } } //it depends on detail type - need specific behaviour for each type //foreach ($value as $dtKey => $dtValue){} } //end switch return $res; } else { return array($dtname => $dtValue); } } else { //name is not defined return null; } }
function print_public_details($bib) { global $terms, $is_map_popup; $bds_res = mysql_query('select dty_ID, ifnull(rdr.rst_DisplayName, dty_Name) as name, dtl_Value as val, dtl_UploadedFileID, dty_Type, if(dtl_Geo is not null, AsWKT(dtl_Geo), null) as dtl_Geo, if(dtl_Geo is not null, AsWKT(envelope(dtl_Geo)), null) as bd_geo_envelope from recDetails left join defDetailTypes on dty_ID = dtl_DetailTypeID left join defRecStructure rdr on rdr.rst_DetailTypeID = dtl_DetailTypeID and rdr.rst_RecTypeID = ' . $bib['rec_RecTypeID'] . ' where dtl_RecID = ' . $bib['rec_ID'] . ' order by rdr.rst_DisplayOrder is null, rdr.rst_DisplayOrder, dty_ID, dtl_ID'); $bds = array(); $thumbs = array(); if ($bds_res) { while ($bd = mysql_fetch_assoc($bds_res)) { if ($bd['dty_ID'] == 603) { //DT_FULL_IMAG_URL array_push($thumbs, array('url' => $bd['val'], 'thumb' => HEURIST_BASE_URL . 'common/php/resizeImage.php?db=' . HEURIST_DBNAME . '&file_url=' . $bd['val'])); } if ($bd['dty_Type'] == 'enum') { if (array_key_exists($bd['val'], $terms['termsByDomainLookup']['enum'])) { $term = $terms['termsByDomainLookup']['enum'][$bd['val']]; $bd['val'] = output_chunker(getFullTermLabel($terms, $term, 'enum', false)); //$bd['val'] = output_chunker($terms['termsByDomainLookup']['enum'][$bd['val']][0]); } else { $bd['val'] = ""; } } else { if ($bd['dty_Type'] == 'relationtype') { $term = $terms['termsByDomainLookup']['relation'][$bd['val']]; $bd['val'] = output_chunker(getFullTermLabel($terms, $term, 'relation', false)); //$bd['val'] = output_chunker($terms['termsByDomainLookup']['relation'][$bd['val']][0]); } else { if ($bd['dty_Type'] == 'date') { $bd['val'] = temporalToHumanReadableString($bd['val'], true); $bd['val'] = output_chunker($bd['val']); } else { if ($bd['dty_Type'] == 'resource') { $res = mysql_query('select rec_Title from Records where rec_ID=' . intval($bd['val'])); $row = mysql_fetch_row($res); $bd['val'] = '<a target="_new" href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['val'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($row[0]) . '</a>'; } else { if ($bd['dty_Type'] == 'file' && $bd['dtl_UploadedFileID']) { //All works with recUploadedFiles MUST be centralized in uploadFile.php $filedata = get_uploaded_file_info($bd['dtl_UploadedFileID'], false); if ($filedata) { $filedata = $filedata['file']; $remoteSrc = $filedata['remoteSource']; //add to thumbnail list $isplayer = array_key_exists('playerURL', $filedata) && $filedata['playerURL']; if (is_image($filedata) || $isplayer) { if ($isplayer && is_image($filedata) && is_logged_in()) { $filedata['playerURL'] .= "&annedit=yes"; } array_push($thumbs, array('id' => $filedata['id'], 'url' => $filedata['URL'], 'thumb' => $filedata['thumbURL'], 'player' => $isplayer ? $filedata['playerURL'] . ($remoteSrc == 'youtube' || $remoteSrc == 'gdrive' ? "" : "&height=60%") : null)); } if ($filedata['URL'] == $filedata['remoteURL']) { //remote resource $bd['val'] = '<a target="_surf" class="external-link" href="' . htmlspecialchars($filedata['URL']) . '">' . htmlspecialchars($filedata['URL']) . '</a>'; } else { $bd['val'] = '<a target="_surf" class="external-link" href="' . htmlspecialchars($filedata['URL']) . '">' . htmlspecialchars($filedata['origName']) . '</a> ' . ($filedata['fileSize'] > 0 ? '[' . htmlspecialchars($filedata['fileSize']) . 'kB]' : ''); } } } else { if (preg_match('/^https?:/', $bd['val'])) { if (strlen($bd['val']) > 100) { $trim_url = preg_replace('/^(.{70}).*?(.{20})$/', '\\1...\\2', $bd['val']); } else { $trim_url = $bd['val']; } $bd['val'] = '<a href="' . $bd['val'] . '" target="_new">' . htmlspecialchars($trim_url) . '</a>'; } else { if ($bd['dtl_Geo'] && preg_match("/^POLYGON\\s?[(][(]([^ ]+) ([^ ]+),[^,]*,([^ ]+) ([^,]+)/", $bd["bd_geo_envelope"], $poly)) { list($match, $minX, $minY, $maxX, $maxY) = $poly; if ($bd["val"] == "l" && preg_match("/^LINESTRING\\s?[(]([^ ]+) ([^ ]+),.*,([^ ]+) ([^ ]+)[)]\$/", $bd["dtl_Geo"], $matches)) { list($dummy, $minX, $minY, $maxX, $maxY) = $matches; } /* redundant $minX = intval($minX*10)/10; $minY = intval($minY*10)/10; $maxX = intval($maxX*10)/10; $maxY = intval($maxY*10)/10; */ switch ($bd["val"]) { case "p": $type = "Point"; break; case "pl": $type = "Polygon"; break; case "c": $type = "Circle"; break; case "r": $type = "Rectangle"; break; case "l": $type = "Path"; break; default: $type = "Unknown"; } if ($type == "Point") { $bd["val"] = "<b>Point</b> " . round($minX, 7) . ", " . round($minY, 7); } else { $bd['val'] = "<b>{$type}</b> X " . round($minX, 7) . ", " . round($maxX, 7) . " Y " . round($minY, 7) . ", " . round($maxY, 7); } $geoimage = "<img class='geo-image' src='" . HEURIST_BASE_URL . "common/images/geo.gif' onmouseout='{if(mapViewer){mapViewer.hide();}}' " . "onmouseover='{if(mapViewer){mapViewer.showAtStatic(event, " . $bib['rec_ID'] . ");}}'> "; $bd['val'] = $geoimage . $bd['val']; } else { $bd['val'] = output_chunker($bd['val']); } } } } } } } array_push($bds, $bd); } } if ($is_map_popup) { echo '<div>'; } else { echo '<div class=detailRowHeader>Shared'; } ?> <div class=thumbnail> <?php foreach ($thumbs as $thumb) { print '<div class=thumb_image>'; if ($thumb['player'] && !$is_map_popup) { print '<img id="img' . $thumb['id'] . '" src="' . htmlspecialchars($thumb['thumb']) . '" onClick="showPlayer(this,' . $thumb['id'] . ',\'' . htmlspecialchars($thumb['player']) . '\')">'; print '<div id="player' . $thumb['id'] . '" style="min-height:240px;min-width:320px;display:none;"></div>'; } else { //for usual image print '<img src="' . htmlspecialchars($thumb['thumb']) . '" onClick="zoomInOut(this,\'' . htmlspecialchars($thumb['thumb']) . '\',\'' . htmlspecialchars($thumb['url']) . '\')">'; } print '<br/><div class="download_link">'; if ($thumb['player'] && !$is_map_popup) { print '<a id="lnk' . $thumb['id'] . '" href="#" style="display:none;" onclick="hidePlayer(' . $thumb['id'] . ')">CLOSE</a> '; } print '<a href="' . htmlspecialchars($thumb['url']) . '" target=_surf class="image_tool">DOWNLOAD</a></div>'; print '</div>'; if ($is_map_popup) { print '<br>'; break; //in map popup show the only thumbnail } } ?> </div> <?php $always_visible_dt = array(defined('DT_NAME') ? DT_SHORT_SUMMARY : 0, defined('DT_NAME') ? DT_GEO_OBJECT : 0); $prevLbl = null; foreach ($bds as $bd) { print '<div class="detailRow" style="width:100%;border:none 1px #00ff00;' . ($is_map_popup && !in_array($bd['dty_ID'], $always_visible_dt) ? 'display:none' : '') . '"><div class=detailType>' . ($prevLbl == $bd['name'] ? "" : htmlspecialchars($bd['name'])) . '</div><div class="detail' . ($is_map_popup && $bd['dty_ID'] != DT_SHORT_SUMMARY ? ' truncate' : '') . '">' . $bd['val'] . '</div></div>'; $prevLbl = $bd['name']; } ?> <div class=detailRow <?php echo $is_map_popup ? 'style="display:none"' : ''; ?> > <div class=detailType>Updated</div><div class=detail><?php echo $bib['rec_Modified']; ?> </div> </div> <div class=detailRow <?php echo $is_map_popup ? 'style="display:none"' : ''; ?> > <div class=detailType>Cite as</div><div class="detail<?php echo $is_map_popup ? ' truncate' : ''; ?> "><a target=_blank class="external-link" href="<?php echo HEURIST_BASE_URL; ?> ?recID=<?php echo $bib['rec_ID'] . "&db=" . HEURIST_DBNAME; ?> "> <?php echo HEURIST_BASE_URL; ?> ?recID=<?php echo $bib['rec_ID'] . "&db=" . HEURIST_DBNAME; ?> </a></div> </div> <?php // </div> if ($is_map_popup) { echo '<div class=detailRow><div class=detailType><a href="#" onClick="$(\'.detailRow\').show();$(event.target).hide()">more ...</a></div></div>'; echo '<div class=detailRow> </div>'; } echo '</div>'; }