Esempio n. 1
0
 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_relation_details($bib)
{
    global $relRT, $relSrcDT, $relTrgDT, $ACCESSABLE_OWNER_IDS, $is_map_popup, $rectypesStructure;
    $from_res = mysql_query('select recDetails.*
            from recDetails
            left join Records on rec_ID = dtl_RecID
            where dtl_DetailTypeID = ' . $relSrcDT . ' and rec_RecTypeID = ' . $relRT . ' and dtl_Value = ' . $bib['rec_ID']);
    //primary resource
    $to_res = mysql_query('select recDetails.*
            from recDetails
            left join Records on rec_ID = dtl_RecID
            where dtl_DetailTypeID = ' . $relTrgDT . ' and rec_RecTypeID = ' . $relRT . ' and dtl_Value = ' . $bib['rec_ID']);
    //linked resource
    if (mysql_num_rows($from_res) <= 0 && mysql_num_rows($to_res) <= 0) {
        return;
    }
    if ($is_map_popup) {
        print '<div>';
    } else {
        print '<div class=detailRowHeader>Related';
    }
    $accessCondition = (count($ACCESSABLE_OWNER_IDS) > 0 ? '(rec_OwnerUGrpID in (' . join(',', $ACCESSABLE_OWNER_IDS) . ') ' : '(0 ') . (is_logged_in() ? 'OR NOT rec_NonOwnerVisibility = "hidden")' : 'OR rec_NonOwnerVisibility = "public")');
    while ($reln = mysql_fetch_assoc($from_res)) {
        $bd = fetch_relation_details($reln['dtl_RecID'], true);
        // check related record
        if (!@$bd['RelatedRecID'] || !array_key_exists('rec_ID', $bd['RelatedRecID'])) {
            continue;
        }
        $relatedRecID = $bd['RelatedRecID']['rec_ID'];
        if (count(mysql__select_array("Records", "rec_ID", "rec_ID = {$relatedRecID} and {$accessCondition}")) == 0) {
            //related is not accessable
            continue;
        }
        print '<div class=detailRow>';
        //		print '<span class=label>' . htmlspecialchars($bd['RelationType']) . '</span>';	//saw Enum change
        if (array_key_exists('RelTerm', $bd)) {
            print '<div class=detailType>' . htmlspecialchars($bd['RelTerm']) . '</div>';
            // fetch now returns the enum string also
        }
        print '<div class=detail>';
        if (@$bd['RelatedRecID']) {
            if (true || $is_map_popup) {
                print '<img class="rft" style="background-image:url(' . HEURIST_ICON_URL . $bd['RelatedRecID']['rec_RecTypeID'] . '.png)" title="' . $rectypesStructure['names'][$bd['RelatedRecID']['rec_RecTypeID']] . '" src="' . HEURIST_BASE_URL . 'common/images/16x16.gif">&nbsp;';
            }
            print '<a target=_new href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['RelatedRecID']['rec_ID'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($bd['RelatedRecID']['rec_Title']) . '</a>';
        } else {
            print htmlspecialchars($bd['Title']);
        }
        print '&nbsp;&nbsp;';
        if (@$bd['StartDate']) {
            print htmlspecialchars(temporalToHumanReadableString($bd['StartDate']));
        }
        if (@$bd['EndDate']) {
            print ' until ' . htmlspecialchars(temporalToHumanReadableString($bd['EndDate']));
        }
        print '</div></div>';
    }
    while ($reln = mysql_fetch_assoc($to_res)) {
        $bd = fetch_relation_details($reln['dtl_RecID'], false);
        // check related record
        if (!@$bd['RelatedRecID'] || !array_key_exists('rec_ID', $bd['RelatedRecID'])) {
            continue;
        }
        $relatedRecID = $bd['RelatedRecID']['rec_ID'];
        if (count(mysql__select_array("Records", "rec_ID", "rec_ID = {$relatedRecID} and {$accessCondition}")) == 0) {
            //related is not accessable
            continue;
        }
        print '<div class=detailRow>';
        //		print '<span class=label>' . htmlspecialchars($bd['RelationType']) . '</span>';	//saw Enum change
        if (array_key_exists('RelTerm', $bd)) {
            print '<div class=detailType>' . htmlspecialchars($bd['RelTerm']) . '</div>';
        }
        print '<div class=detail>';
        if (@$bd['RelatedRecID']) {
            if (true || $is_map_popup) {
                print '<img class="rft" style="background-image:url(' . HEURIST_ICON_URL . $bd['RelatedRecID']['rec_RecTypeID'] . '.png)" title="' . $rectypesStructure['names'][$bd['RelatedRecID']['rec_RecTypeID']] . '" src="' . HEURIST_BASE_URL . 'common/images/16x16.gif">&nbsp;';
            }
            print '<a target=_new href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['RelatedRecID']['rec_ID'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($bd['RelatedRecID']['rec_Title']) . '</a>';
        } else {
            print htmlspecialchars($bd['Title']);
        }
        print '&nbsp;&nbsp;';
        if (@$bd['StartDate']) {
            print htmlspecialchars($bd['StartDate']);
        }
        if (@$bd['EndDate']) {
            print ' until ' . htmlspecialchars($bd['EndDate']);
        }
        print '</div></div>';
    }
}
/**
* retuns value of given detail id for record id
*
* @param mixed $rec_id
* @param mixed $rdt_id - detail type id
* @return mixed
*/
function _title_mask__get_rec_detail($rec_id, $rdt_id)
{
    static $rec_details;
    if (!$rec_details) {
        $rec_details = array();
    }
    if (array_key_exists($rec_id, $rec_details) && array_key_exists($rdt_id, $rec_details[$rec_id]) && $rec_details[$rec_id][$rdt_id] != "") {
        return $rec_details[$rec_id][$rdt_id];
    }
    $rdt = _title_mask__get_rec_detail_types();
    $rec_details[$rec_id] = array();
    $res = mysql_query('select recDetails.* from recDetails' . ' where dtl_RecID = ' . intval($rec_id) . ' order by dtl_ID asc');
    while ($rd = mysql_fetch_assoc($res)) {
        $rdt_type = $rdt[$rd['dtl_DetailTypeID']]['dty_Type'];
        if ($rdt_type == 'file') {
            /* handle files specially */
            if (@$rec_details[$rec_id][$rd['dtl_DetailTypeID']]) {
                // repeated values
                $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = intval($rec_details[$rec_id][$rd['dtl_DetailTypeID']]) + 1 . ' files';
            } else {
                $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = '1 file';
            }
        } else {
            if ($rdt_type == 'geo') {
                /* handle geographic objects specially */
                if (@$rec_details[$rec_id][$rd['dtl_DetailTypeID']]) {
                    // repeated values
                    $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = intval($rec_details[$rec_id][$rd['dtl_DetailTypeID']]) + 1 . ' geographic objects';
                } else {
                    $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = '1 geographic object';
                }
            } else {
                if ($rdt_type == 'date') {
                    /* handle date objects specially */
                    $str = trim($rd['dtl_Value']);
                    $str = temporalToHumanReadableString($str);
                    /*
                    			if (strlen($str) > 0 && preg_match("/\|VER/",$str)) { // we have a temporal
                    				preg_match("/TYP=([s|p|c|f|d])/",$str,$typ);
                    				switch  ($typ[1]) {
                    					case 's': // simple date
                    						preg_match("/DAT=([^\|]+)/",$str,$dat);
                    						$dat = (count($dat)>1 && $dat[1]) ? $dat[1] : null;
                    						preg_match("/COM=([^\|]+)/",$str,$com);
                    						$com = (count($com)>1 && $com[1]) ? $com[1] : null;
                    						$str = $dat ? $dat :($com ? $com:"temporal simple date");
                    						break;
                    					case 'p': // probable date
                    						preg_match("/TPQ=([^\|]+)/",$str,$tpq);
                    						$tpq = (count($tpq)>1 && $tpq[1]) ? $tpq[1] : null;
                    						preg_match("/TAQ=([^\|]+)/",$str,$taq);
                    						$taq = (count($taq)>1 && $taq[1]) ? $taq[1] : null;
                    						preg_match("/PDB=([^\|]+)/",$str,$pdb);
                    						$pdb = (count($pdb)>1 && $pdb[1]) ? $pdb[1] :($tpq ? $tpq:"");
                    						preg_match("/PDE=([^\|]+)/",$str,$pde);
                    						$pde = (count($pde)>1 && $pde[1]) ? $pde[1] :($taq ? $taq:"");
                    						$str = $pdb . " – " . $pde;
                    						break;
                    					case 'c': //c14 date
                    						preg_match("/BCE=([^\|]+)/",$str,$bce);
                    						$bce = (count($bce)>1 && @$bce[1]) ? $bce[1] : null;
                    						preg_match("/BPD=([^\|]+)/",$str,$c14);
                    						$c14 = @$c14[1] ? $c14[1] :(@$bce ? $bce:" c14 temporal");
                    						$suff = preg_match("/CAL=/",$str) ? " Cal" : "";
                    						$suff .= $bce ? " BCE" : " BP";
                    						preg_match("/DVP=P(\d+)Y/",$str,$dvp);
                    						$dvp = (count($dvp)>1 && $dvp[1]) ? $dvp[1] : null;
                    						preg_match("/DEV=P(\d+)Y/",$str,$dev);
                    						$dev = $dev ? " ±" . $dev[1]. " yr". ($dev[1]>1?"s":""):($dvp ? " +" . $dvp . " yr" . ($dvp>1?"s":""):" + ??");
                    						preg_match("/DVN=P(\d+)Y/",$str,$dvn);
                    						$dev .= $dvp ? ($dvn[1] ? " -" . $dvn[1] . " yr" . ($dvn[1]>1?"s":""): " - ??") : "";
                    						$str = "(" . $c14 . $dev . $suff . ")";
                    						break;
                    					case 'f': //fuzzy date
                    						preg_match("/DAT=([^\|]+)/",$str,$dat);
                    						$dat = (count($dat)>1 && $dat[1]) ? $dat[1] : null;
                    						preg_match("/RNG=P(\d*)(Y|M|D)/",$str,$rng);
                    //						error_log("title mask match rng - ".print_r($rng,true));
                    						$units = ($rng[2] ? ($rng[2]=="Y" ? "year" : ($rng[2]=="M" ? "month" : ($rng[2]=="D" ? "day" :""))): "");
                    						$rng = ($rng && $rng[1] ? " ± " . $rng[1] . " " . ($units ? $units . ($rng[1]>1 ? "s":""):""): "");
                    						$str = $dat . $rng;
                    						break;
                    					default:
                    						$str = "temporal encoded time";
                    				}
                    			}
                    */
                    if (@$rec_details[$rec_id][$rd['dtl_DetailTypeID']]) {
                        // repeated values
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']] .= ', ' . $str;
                    } else {
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = $str;
                    }
                } else {
                    if ($rdt_type == 'enum' || $rdt_type == 'relationtype') {
                        //substitute term for it's id
                        $ress = mysql_query("select trm_Label from defTerms where trm_ID = " . $rd['dtl_Value']);
                        if (!mysql_error()) {
                            $relval = mysql_fetch_assoc($ress);
                            $rd['dtl_Value'] = $relval['trm_Label'];
                        }
                        /*
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = 'enum';
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']]['id'] = 'label enum';
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']]['code']
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']]['label']
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']]['conceptid']
                        */
                    }
                    if (@$rec_details[$rec_id][$rd['dtl_DetailTypeID']]) {
                        // repeated values
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']] .= ', ' . $rd['dtl_Value'];
                    } else {
                        $rec_details[$rec_id][$rd['dtl_DetailTypeID']] = $rd['dtl_Value'];
                    }
                }
            }
        }
    }
    return @$rec_details[$rec_id][$rdt_id];
}
Esempio n. 4
0
function _titlemask__get_field_value($rdt_id, $rt, $mode, $rec_id, $enum_param_name = null)
{
    if ($mode == 0) {
        $rec_values = _titlemask__get_record_value($rec_id);
        if (!$rec_values) {
            return "";
        } else {
            if (strcasecmp($rdt_id, 'id') == 0) {
                return $rec_values['rec_ID'];
            } else {
                if (strcasecmp($rdt_id, 'rectitle') == 0) {
                    return $rec_values['rec_Title'];
                } else {
                    if (strcasecmp($rdt_id, 'rectypeid') == 0) {
                        return $rec_values['rec_RecTypeID'];
                    } else {
                        if (strcasecmp($rdt_id, 'rectypename') == 0) {
                            return $rec_values['rty_Name'];
                        } else {
                            if (strcasecmp($rdt_id, 'modified') == 0) {
                                return $rec_values['rec_Modified'];
                            }
                        }
                    }
                }
            }
        }
        $rdt_id = _titlemask__get_dt_field($rt, $rdt_id, $mode, 'dty_ID');
        //local dt id
        $dt_type = _titlemask__get_dt_field($rt, $rdt_id, $mode, 'dty_Type');
        $details = $rec_values['rec_Details'];
        $res = array();
        $found = false;
        foreach ($details as $detail) {
            if ($detail[0] == $rdt_id) {
                $found = true;
                if ($dt_type == "enum" || $dt_type == "relationtype") {
                    $value = _titlemask__get_enum_value($detail[1], $enum_param_name);
                } else {
                    if ($dt_type == "date") {
                        $value = temporalToHumanReadableString(trim($detail[1]));
                    } else {
                        $value = $detail[1];
                    }
                }
                if ($value) {
                    array_push($res, $value);
                }
            } else {
                if ($found) {
                    break;
                }
            }
        }
        if (count($res) == 0) {
            return "";
        } else {
            if ($dt_type == 'file') {
                return count($res) . " file" . (count($res) > 1 ? "s" : "");
            } else {
                if ($dt_type == 'geo') {
                    return count($res) . " geographic object" . (count($res) > 1 ? "s" : "");
                } else {
                    return implode(",", $res);
                }
            }
        }
    } else {
        if (strcasecmp($rdt_id, 'id') == 0 || strcasecmp($rdt_id, 'rectitle') == 0 || strcasecmp($rdt_id, 'modified') == 0) {
            return $rdt_id;
        } else {
            if ($mode == 1) {
                //convert to
                return $rdt_id;
                //concept code
            } else {
                return _titlemask__get_dt_field($rt, $rdt_id, $mode, 'originalName');
                //original name (with capital chars)
            }
        }
    }
}
function print_relation_details($bib)
{
    global $relRT, $relSrcDT, $relTrgDT;
    $from_res = mysql_query('select recDetails.*
	                           from recDetails
	                      left join Records on rec_ID = dtl_RecID
	                          where dtl_DetailTypeID = ' . $relSrcDT . ' and rec_RecTypeID = ' . $relRT . ' and dtl_Value = ' . $bib['rec_ID']);
    //primary resource
    $to_res = mysql_query('select recDetails.*
	                         from recDetails
	                    left join Records on rec_ID = dtl_RecID
	                        where dtl_DetailTypeID = ' . $relTrgDT . ' and rec_RecTypeID = ' . $relRT . ' and dtl_Value = ' . $bib['rec_ID']);
    //linked resource
    if (mysql_num_rows($from_res) <= 0 && mysql_num_rows($to_res) <= 0) {
        return;
    }
    ?>
</div>
<div class=detailRowHeader>Related
<?php 
    while ($reln = mysql_fetch_assoc($from_res)) {
        $bd = fetch_relation_details($reln['dtl_RecID'], true);
        print '<div class=detailRow>';
        //		print '<span class=label>' . htmlspecialchars($bd['RelationType']) . '</span>';	//saw Enum change
        if (array_key_exists('RelTerm', $bd)) {
            print '<div class=detailType>' . htmlspecialchars($bd['RelTerm']) . '</div>';
            // fetch now returns the enum string also
        }
        print '<div class=detail>';
        if (@$bd['RelatedRecID']) {
            print '<a target=_new href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['RelatedRecID']['rec_ID'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($bd['RelatedRecID']['rec_Title']) . '</a>';
        } else {
            print htmlspecialchars($bd['Title']);
        }
        print '&nbsp;&nbsp;';
        if (@$bd['StartDate']) {
            print htmlspecialchars(temporalToHumanReadableString($bd['StartDate']));
        }
        if (@$bd['EndDate']) {
            print ' until ' . htmlspecialchars(temporalToHumanReadableString($bd['EndDate']));
        }
        print '</div></div>';
    }
    while ($reln = mysql_fetch_assoc($to_res)) {
        $bd = fetch_relation_details($reln['dtl_RecID'], false);
        print '<div class=detailRow>';
        //		print '<span class=label>' . htmlspecialchars($bd['RelationType']) . '</span>';	//saw Enum change
        if (array_key_exists('RelTerm', $bd)) {
            print '<div class=detailType>' . htmlspecialchars($bd['RelTerm']) . '</div>';
        }
        print '<div class=detail>';
        if (@$bd['RelatedRecID']) {
            print '<a target=_new href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['RelatedRecID']['rec_ID'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($bd['RelatedRecID']['rec_Title']) . '</a>';
        } else {
            print htmlspecialchars($bd['Title']);
        }
        print '&nbsp;&nbsp;';
        if (@$bd['StartDate']) {
            print htmlspecialchars($bd['StartDate']);
        }
        if (@$bd['EndDate']) {
            print ' until ' . htmlspecialchars($bd['EndDate']);
        }
        print '</div></div>';
    }
}
Esempio n. 6
0
function getDetailForSmarty($dtKey, $dtValue, $recursion_depth, $recTypeID, $recID)
{
    global $dtStructs, $dtTerms, $rtStructs;
    $dtNames = $dtStructs['names'];
    $rtNames = $rtStructs['names'];
    $dty_fi = $dtStructs['typedefs']['fieldNamesToIndex'];
    /*****DEBUG****/
    //	if($dtKey==9){
    /*****DEBUG****/
    //error_log("KEY=".$dtKey."   NAME=".$dtNames[$dtKey]);
    /*****DEBUG****/
    //error_log("dtValue=".print_r($dtValue, true));
    /*****DEBUG****/
    //	}
    if ($dtKey < 1 || $dtNames[$dtKey]) {
        if ($dtKey < 1) {
            $dt_label = "Relationship";
            /*****DEBUG****/
            //error_log("111>>>>>".print_r($dtValue, true));
            /*****DEBUG****/
            //error_log("222>>>>>".$recTypeID);
        } else {
            $rt_structure = $rtStructs['typedefs'][$recTypeID]['dtFields'];
            $dtlabel_index = $rtStructs['typedefs']['dtFieldNamesToIndex']['rst_DisplayName'];
            if (array_key_exists($dtKey, $rt_structure)) {
                $dt_label = $rt_structure[$dtKey][$dtlabel_index];
                //$dtname = getVariableNameForSmarty($dt_label);
            }
            $dtname = getVariableNameForSmarty($dtNames[$dtKey]);
        }
        if (is_array($dtValue)) {
            //complex type - need more analize
            $res = null;
            $dtDef = $dtKey < 1 ? "dummy" : $dtStructs['typedefs'][$dtKey]['commonFields'];
            if ($dtDef) {
                $detailType = $dtKey < 1 ? "relmarker" : $dtDef[$dty_fi['dty_Type']];
                switch ($detailType) {
                    case 'enum':
                        $fi = $dtTerms['fieldNamesToIndex'];
                        $res_id = "";
                        $res_cid = "";
                        $res_code = "";
                        $res_label = "";
                        foreach ($dtValue as $key => $value) {
                            if (array_key_exists($value, $dtTerms['termsByDomainLookup']['enum'])) {
                                $term = $dtTerms['termsByDomainLookup']['enum'][$value];
                                $res_id = _add_term_val($res_id, $value);
                                $res_cid = _add_term_val($res_cid, $term[$fi['trm_ConceptID']]);
                                $res_code = _add_term_val($res_code, $term[$fi['trm_Code']]);
                                $res_label = _add_term_val($res_label, $term[$fi['trm_Label']]);
                            }
                        }
                        $res = array("id" => $res_id, "code" => $res_code, "label" => $res_label, "conceptid" => $res_cid);
                        $res = array($dtname => $res);
                        /*if(strlen($res)==0){ //no valid terms
                        			$res = null;
                        		}else{
                        			$res = array( $dtname=>$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']);
                            //$dtname2 = $dtname."_originalvalue";
                            //$arres = array_merge($arres, array($dtname2=>$value['file']));
                            /*****DEBUG****/
                            //error_log(">>>>>".$dtname2."= ".print_r($value['file'],true));
                        }
                        if (strlen($res) == 0) {
                            $res = null;
                        } else {
                            $res = array($dtname => $res, $dtname . "_originalvalue" => $origvalues);
                            //array_merge($arres, array($dtname=>$res));
                        }
                        break;
                        /* NOT USED ANYMORE
                        			case 'urlinclude':
                        				//
                        				$res = "";
                        				$arres = array();
                        
                        				foreach ($dtValue as $key => $value){
                        					if(strlen($res)>0) $res = $res.", ";
                        
                        					$arr = explode('|', $value);
                        					$res = $res.$arr[0];
                        
                        					//original value keeps source and type
                        					$dtname2 = $dtname."_originalvalue";
                        					$arres = array_merge($arres, array($dtname2=>$value));
                        				}
                        				if(strlen($res)==0){
                        					$res = null;
                        				}else{
                        					$res = array_merge($arres, array($dtname=>$res));
                        				}
                        
                        			break;
                        */
                    /* NOT USED ANYMORE
                    			case 'urlinclude':
                    				//
                    				$res = "";
                    				$arres = array();
                    
                    				foreach ($dtValue as $key => $value){
                    					if(strlen($res)>0) $res = $res.", ";
                    
                    					$arr = explode('|', $value);
                    					$res = $res.$arr[0];
                    
                    					//original value keeps source and type
                    					$dtname2 = $dtname."_originalvalue";
                    					$arres = array_merge($arres, array($dtname2=>$value));
                    				}
                    				if(strlen($res)==0){
                    					$res = null;
                    				}else{
                    					$res = array_merge($arres, array($dtname=>$res));
                    				}
                    
                    			break;
                    */
                    case 'geo':
                        $res = "";
                        $arres = array();
                        foreach ($dtValue as $key => $value) {
                            /*****DEBUG****/
                            //error_log("GEO=>>>>".print_r($value, true));
                            //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
                            /*
                            						$geom = geoPHP::load($value['geo']['wkt'],'wkt');
                            						if(!$geom->isEmpty()){
                            							$point = $geom->centroid();
                            							$res = "http://maps.google.com/maps?z=18&q=".$point->y().",".$point->x();
                            							break;
                            						}*/
                        }
                        if (strlen($res) == 0) {
                            $res = null;
                        } else {
                            $res = array_merge($arres, array($dtname => $res));
                            //$res = array( $dtname=>$res );
                        }
                        break;
                    case 'separator':
                        break;
                    case 'calculated':
                        break;
                    case 'fieldsetmarker':
                        break;
                    case 'relmarker':
                    case 'resource':
                        // link to another record type
                        //@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;
                        /*****DEBUG****/
                        //error_log("dtValue>>>>>".print_r($dtValue,true));
                        $order = 0;
                        foreach ($dtValue as $key => $value) {
                            if ($recursion_depth < 2 && (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'];
                                    /*****DEBUG****/
                                    //error_log(">>>>value=".print_r($value, true));
                                } else {
                                    $recordID = $value['id'];
                                }
                                //get full record info
                                $record = loadRecord($recordID);
                                //from search/getSearchResults.php
                                $res0 = null;
                                if (true) {
                                    //64719  45171   48855    57247
                                    $res0 = getRecordForSmarty($record, $recursion_depth + 2, $order);
                                    //@todo - need to
                                    $order++;
                                }
                                if ($res0) {
                                    if ($rectypeID == null && @$res0['recRecTypeID']) {
                                        $rectypeID = $res0['recRecTypeID'];
                                        /* TEMP DEBUG
                                        								if(array_key_exists($rectypeID, $rtNames))
                                        								{
                                        									$pointerIDs = ($dtKey<1) ?"" :$dtDef[ $dty_fi['dty_PtrTargetRectypeIDs'] ];
                                        									$isunconstrained = ($pointerIDs=="");
                                        if($isunconstrained){
                                        /*****DEBUG****/
                                        //error_log($dt_label.">>>>>>>");
                                        /*}
                                        		}            */
                                    }
                                    //add relationship specific variables
                                    if (array_key_exists('RelatedRecID', $value) && array_key_exists('RelTerm', $value)) {
                                        $res0["recRelationType"] = $value['RelTerm'];
                                        /*if(array_key_exists('interpRecID', $value)){
                                        			$record = loadRecord($value['interpRecID']);
                                        			$res0["recRelationInterpretation"] = getRecordForSmarty($record, $recursion_depth+2, $order);
                                        		}*/
                                        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']);
                                        }
                                        /*****DEBUG****/
                                        //error_log(">>>>RECID=".$recordID." >>>>>".print_r($res0, true));
                                    }
                                    array_push($res, $res0);
                                }
                            }
                        }
                        //for each repeated value
                        if (count($res) > 0 && array_key_exists($rectypeID, $rtNames)) {
                            $pointerIDs = $dtKey < 1 ? "" : $dtDef[$dty_fi['dty_PtrTargetRectypeIDs']];
                            /*if($pointerIDs==""){ //unconstrainted pointer - we will use as name of variable display name for current record type
                            			$recordTypeName = $dt_label;
                            		}else{
                            			$recordTypeName = $rtNames[$rectypeID];
                            		}*/
                            if (@$dt_label) {
                                $recordTypeName = $dt_label;
                                $recordTypeName = getVariableNameForSmarty($recordTypeName, false);
                                $res = array($recordTypeName . "s" => $res, $recordTypeName => $res[0]);
                            }
                        } 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;
    }
}