public function getRecord($rec, $smarty_obj = null) { if (is_array($rec) && $rec['recID']) { $rec_ID = $rec['recID']; } else { $rec_ID = $rec; } if (@$this->loaded_recs[$rec_ID]) { return $this->loaded_recs[$rec_ID]; } $rec = loadRecord($rec_ID, false, true); //from search/getSearchResults.php $res1 = $this->getRecordForSmarty($rec); return $res1; }
function showRollbacks($rollbacks) { $s = count($rollbacks) != 1 ? "s" : ""; print "<p>" . count($rollbacks) . " record{$s} can be rolled back.</p>"; foreach ($rollbacks as $rec_id => $changes) { $record = loadRecord($rec_id); showRecordRollback($record, $changes); } }
function outputDetail($dt, $value, $rt, &$reverse_pointers, &$relationships, $depth = 0, $outputStub, $parentID) { global $DTN, $DTT, $TL, $RQS, $INV, $GEO_TYPES, $MAX_DEPTH, $INCLUDE_FILE_CONTENT, $SUPRESS_LOOPBACKS, $relTypDT, $relTrgDT, $relSrcDT; /*****DEBUG****/ //error_log("in outputDetail dt = $dt value = ". print_r($value,true)); $attrs = array('id' => $dt, 'conceptID' => getDetailTypeConceptID($dt)); if (array_key_exists($dt, $DTN)) { $attrs['type'] = $DTN[$dt]; } if (array_key_exists($rt, $RQS) && array_key_exists($dt, $RQS[$rt])) { $attrs['name'] = $RQS[$rt][$dt]; } if ($dt === $relTypDT && array_key_exists($value, $INV) && $INV[$value] && array_key_exists($INV[$value], $TL)) { //saw Enum change $attrs['inverse'] = $TL[$INV[$value]]['trm_Label']; $attrs['invTermConceptID'] = getTermConceptID($INV[$value]); } if (is_array($value)) { if (array_key_exists('id', $value)) { // record pointer if ($dt === $relSrcDT || $dt === $relTrgDT) { // in a relationship record don't expand from side if ($value['id'] == $parentID) { $attrs['direction'] = "from"; if ($dt === $relTrgDT) { $attrs['useInverse'] = 'true'; } if ($SUPRESS_LOOPBACKS) { openTag('detail', $attrs); if ($outputStub) { outputRecordStub(loadRecordStub($value['id'])); } else { echo $value['id']; } closeTag('detail'); return; } } else { $attrs['direction'] = "to"; if ($dt === $relSrcDT) { $attrs['useInverse'] = 'true'; } } openTag('detail', $attrs); outputRecord(loadRecord($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if ($depth < $MAX_DEPTH) { openTag('detail', $attrs); outputRecord(loadRecord($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if ($outputStub) { openTag('detail', $attrs); outputRecordStub(loadRecordStub($value['id'])); closeTag('detail'); } else { makeTag('detail', $attrs, $value['id']); } } } } else { if (array_key_exists('file', $value)) { $file = $value['file']; /*****DEBUG****/ //error_log(" in outputDetail file = \n".print_r($file,true)); openTag('detail', $attrs); openTag('file'); makeTag('id', null, $file['id']); makeTag('nonce', null, $file['nonce']); makeTag('origName', null, $file['origName']); makeTag('type', null, $file['type']); makeTag('size', array('units' => 'kB'), $file['size']); makeTag('date', null, $file['date']); makeTag('description', null, $file['description']); makeTag('url', null, $file['URL']); makeTag('thumbURL', null, $file['thumbURL']); if ($INCLUDE_FILE_CONTENT) { makeFileContentNode($file); } closeTag('file'); closeTag('detail'); } else { if (array_key_exists('geo', $value)) { openTag('detail', $attrs); openTag('geo'); makeTag('type', null, $GEO_TYPES[$value['geo']['type']]); makeTag('wkt', null, $value['geo']['wkt']); closeTag('geo'); closeTag('detail'); } } } } else { if ($DTT[$dt] === 'date') { openTag('detail', $attrs); if (strpos($value, "|") === false) { outputDateDetail($attrs, $value); } else { outputTemporalDetail($attrs, $value); } closeTag('detail'); } else { if ($DTT[$dt] === 'resource') { openTag('detail', $attrs); outputRecord(loadRecord($value), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if (($DTT[$dt] === 'enum' || $DTT[$dt] === 'relationtype') && array_key_exists($value, $TL)) { $attrs['termConceptID'] = getTermConceptID($value); if (@$TL[$value]['trm_ParentTermID']) { $attrs['ParentTerm'] = $TL[$TL[$value]['trm_ParentTermID']]['trm_Label']; } /*****DEBUG****/ //error_log("value = ".$value." label = ".$TL[$value]['trm_Label']); makeTag('detail', $attrs, $TL[$value]['trm_Label']); } else { makeTag('detail', $attrs, replaceIllegalChars($value)); } } } } }
function loadSearch($args, $bare = false, $onlyIDs = false, $publicOnly = false) { /* * Three basic steps are involved here: * * 1. Execute the query, which results in a list of record IDs * (this step includes authentication, i.e. the results will be only * those records visible to the user). * * 2. Load the core, public data for each record, whether it be from the * cache or from the database. * * 3. Load the user-dependent data for each record (bookmark, tags, comments etc.). * This step is optional - some applications may need only the core data. In this * case they should specify $bare = true. */ if (!@$args["q"]) { return array("error" => "no query specified"); } if (is_logged_in() && @$args["w"] === "bookmark") { $searchType = BOOKMARK; } else { $searchType = BOTH; } $fresh = !!@$args["f"]; $noCache = @$args["nocache"] == 1; $query = REQUEST_to_query("select SQL_CALC_FOUND_ROWS rec_ID ", $searchType, $args, null, $publicOnly); $res = mysql_query($query); if (mysql_error()) { } $fres = mysql_query('select found_rows()'); $resultCount = mysql_fetch_row($fres); $resultCount = $resultCount[0]; if ($onlyIDs) { $row = mysql_fetch_assoc($res); $ids = "" . ($row["rec_ID"] ? $row["rec_ID"] : ""); while ($row = mysql_fetch_assoc($res)) { $ids .= $row["rec_ID"] ? "," . $row["rec_ID"] : ""; } return array("resultCount" => $resultCount, "recordCount" => strlen($ids) ? count(explode(",", $ids)) : 0, "recIDs" => $ids); } else { $recs = array(); while ($row = mysql_fetch_assoc($res)) { if (mysql_error()) { } if ($noCache) { $record = loadRecord_NoCache($row["rec_ID"], $bare); } else { $record = loadRecord($row["rec_ID"], $fresh, $bare); } if (array_key_exists("error", $record)) { return array("error" => $record["error"]); } array_push($recs, $record); } return array("resultCount" => $resultCount, "recordCount" => count($recs), "records" => $recs); } }
/** * description * @global type description of global variable usage in a function * @staticvar type [$varname] description of static variable usage in function * @param type [$varname] description * @return type description * @link URL * @see name of another element (function or object) used in this function * @throws list of exceptions thrown in this code * @uses code_element_name description of use */ function outputRecords($result) { global $OUTPUT_STUBS, $FRESH, $MAX_DEPTH; $recSet = array('count' => 0, 'relatedSet' => array()); $rec_ids = explode(",", $result['recIDs']); if (array_key_exists('expandColl', $_REQUEST)) { $rec_ids = expandCollections($rec_ids); } foreach ($rec_ids as $recID) { $recSet['relatedSet'][$recID] = array('depth' => 0); } buildGraphStructure($rec_ids, $recSet); $recSet['count'] = count($recSet['relatedSet']); foreach ($recSet['relatedSet'] as $recID => $recInfo) { $recSet['relatedSet'][$recID]['record'] = loadRecord($recID, $FRESH, true); } openTag('records', array('count' => $recSet['count'])); foreach ($recSet['relatedSet'] as $recID => $recInfo) { if (intval($recInfo['depth']) <= $MAX_DEPTH) { outputRecord($recInfo, $recSet['relatedSet'], $OUTPUT_STUBS); } } closeTag('records'); }
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; } }