Пример #1
0
 public function getRelatedRecords($rec, $smarty_obj = null)
 {
     if (is_array($rec) && $rec['recID']) {
         $rec_ID = $rec['recID'];
     } else {
         $rec_ID = $rec;
     }
     $relRT = defined('RT_RELATION') ? RT_RELATION : 0;
     $relSrcDT = defined('DT_PRIMARY_RESOURCE') ? DT_PRIMARY_RESOURCE : 0;
     $relTrgDT = defined('DT_TARGET_RESOURCE') ? DT_TARGET_RESOURCE : 0;
     $res = array();
     $rel_records = array();
     /* find related records */
     if ($rec_ID > 0 && $relRT > 0 && $relSrcDT > 0 && $relTrgDT > 0) {
         // get rel records where current record is source
         $from_res = mysql_query('SELECT rl_RelationID as dtl_RecID FROM recLinks WHERE rl_RelationID IS NOT NULL AND rl_SourceID=' . $rec_ID);
         // get rel records where current record is target
         $to_res = mysql_query('SELECT rl_RelationID as dtl_RecID FROM recLinks WHERE rl_RelationID IS NOT NULL AND rl_TargetID=' . $rec_ID);
         /* old slow way                                   
            $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 = ' . $record["recID"]);        //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 = ' . $record["recID"]);          //linked resource
            */
         if (mysql_num_rows($from_res) > 0 || mysql_num_rows($to_res) > 0) {
             //load relationship record details
             while ($reln = mysql_fetch_assoc($from_res)) {
                 $bd = fetch_relation_details($reln['dtl_RecID'], true);
                 array_push($rel_records, $bd);
             }
             while ($reln = mysql_fetch_assoc($to_res)) {
                 $bd = fetch_relation_details($reln['dtl_RecID'], false);
                 array_push($rel_records, $bd);
             }
             foreach ($rel_records as $key => $value) {
                 if (array_key_exists('RelatedRecID', $value) && array_key_exists('RelTerm', $value)) {
                     $record = $this->getRecord($value['RelatedRecID']['rec_ID']);
                     //error_log($value['RelatedRecID']['rec_ID'].'   '.print_r($record,true));
                     //add relationship specific variables
                     $record["recRelationType"] = $value['RelTerm'];
                     if (array_key_exists('Notes', $value)) {
                         $record["recRelationNotes"] = $value['Notes'];
                     }
                     if (array_key_exists('StartDate', $value)) {
                         $record["recRelationStartDate"] = temporalToHumanReadableString($value['StartDate']);
                     }
                     if (array_key_exists('EndDate', $value)) {
                         $record["recRelationEndDate"] = temporalToHumanReadableString($value['EndDate']);
                     }
                     array_push($res, $record);
                 }
             }
         }
     }
     return $res;
 }
Пример #2
0
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>';
    }
}
Пример #3
0
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>';
    }
}
Пример #4
0
function getRecordForSmarty($rec, $recursion_depth, $order)
{
    global $rtStructs;
    if (!$rec) {
        return null;
    } else {
        $relRT = defined('RT_RELATION') ? RT_RELATION : 0;
        $relSrcDT = defined('DT_PRIMARY_RESOURCE') ? DT_PRIMARY_RESOURCE : 0;
        $relTrgDT = defined('DT_TARGET_RESOURCE') ? DT_TARGET_RESOURCE : 0;
        /*****DEBUG****/
        //error_log("RElation constants=".$relRT."  ".$relSrcDT."    ".$relTrgDT);
        $record = array();
        $recTypeID = null;
        /*****DEBUG****/
        //error_log("REC=".print_r($rec, true));
        $record["recOrder"] = $order;
        //loop for all record properties
        foreach ($rec as $key => $value) {
            $pos = strpos($key, "rec_");
            if (is_numeric($pos) && $pos == 0) {
                //array_push($record, array(substr($key,4) => $value));
                $record['rec' . substr($key, 4)] = $value;
                if ($key == "rec_RecTypeID") {
                    //additional field
                    $recTypeID = $value;
                    $record["recTypeName"] = $rtStructs['typedefs'][$value]['commonFields'][$rtStructs['typedefs']['commonNamesToIndex']['rty_Name']];
                } else {
                    if ($key == "rec_ID") {
                        //load woottext once per record
                        $record["recWootText"] = getWootText($value);
                    }
                }
            } else {
                if ($key == "details") {
                    $details = array();
                    foreach ($value as $dtKey => $dtValue) {
                        $dt = getDetailForSmarty($dtKey, $dtValue, $recursion_depth, $recTypeID, $record['recID']);
                        if ($dt) {
                            $record = array_merge($record, $dt);
                        }
                    }
                    //$record['rec'.substr($key,4)] = $details;
                }
            }
        }
        /* find related records */
        if ($relRT > 0 && $relSrcDT > 0 && $relTrgDT > 0) {
            $dtValue = array();
            $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 = ' . $record["recID"]);
            //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 = ' . $record["recID"]);
            //linked resource
            if (mysql_num_rows($from_res) > 0 || mysql_num_rows($to_res) > 0) {
                while ($reln = mysql_fetch_assoc($from_res)) {
                    $bd = fetch_relation_details($reln['dtl_RecID'], true);
                    array_push($dtValue, $bd);
                }
                while ($reln = mysql_fetch_assoc($to_res)) {
                    $bd = fetch_relation_details($reln['dtl_RecID'], false);
                    array_push($dtValue, $bd);
                }
                $dt = getDetailForSmarty(-1, $dtValue, $recursion_depth, $recTypeID, $record["recID"]);
                if ($dt) {
                    $record = array_merge($record, $dt);
                }
            }
            /* OLD WAY
            			if($relSrcDT>0){
            
            				//current record is source
            				$rel_query = "select r2.dtl_Value as id from recDetails r1 left join recDetails r2 on r1.dtl_RecID = r2.dtl_RecID and r2.dtl_DetailTypeID = $relTrgDT
            where r1.dtl_DetailTypeID = $relSrcDT and r1.dtl_Value = ".$record["recID"];
            
            				$to_res = mysql_query($rel_query);
            
            				while ($reln = mysql_fetch_assoc($to_res)) {
            					array_push($dtValue, $reln);
            					$k++;
            				}//while
            
            			}
            
            			if($relTrgDT>0){
            				//current record is target
            				$rel_query = "select r2.dtl_Value as id from recDetails r1 left join recDetails r2 on r1.dtl_RecID = r2.dtl_RecID and r2.dtl_DetailTypeID = $relSrcDT
            where r1.dtl_DetailTypeID = $relTrgDT and r1.dtl_Value = ".$record["recID"];
            
            				$to_res = mysql_query($rel_query);
            
            				while ($reln = mysql_fetch_assoc($to_res)) {
            					array_push($dtValue, $reln);
            					$k++;
            				}//while
            			}
            
            			if($k>1){
            					$dt = getDetailForSmarty(-1,$dtValue, $recursion_depth, $recTypeID, $record["recID"]);
            					if($dt){
            						$record = array_merge($record, $dt);
            					}
            			}
            			*/
        }
        return $record;
    }
}