function updateTitleMask($rtyID, $mask) { global $mysqli; $ret = 0; if ($mask) { $parameters = array(""); $val = titlemask_make($mask, $rtyID, 1, null, _ERR_REP_SILENT); //make coded $parameters = addParam($parameters, "s", $val); /* DEPRECATED $colName = "rty_CanonicalTitleMask"; $parameters[0] = "ss";//$parameters[0].$rtyColumnNames[$colName]; array_push($parameters, $val); rty_CanonicalTitleMask = ?, */ $query = "update defRecTypes set rty_TitleMask = ? where rty_ID = {$rtyID}"; $res = execSQL($mysqli, $query, $parameters, true); if (!is_numeric($res)) { $ret = "SQL error updating record type {$rtyID} in updateTitleMask: " . $res; } } return $ret; }
require_once dirname(__FILE__) . '/../../../common/connect/applyCredentials.php'; require_once dirname(__FILE__) . '/../../../common/php/dbMySqlWrappers.php'; require_once dirname(__FILE__) . '/../../../common/php/utilsTitleMask.php'; //require_once(dirname(__FILE__).'/../../../common/php/utilsTitleMaskOld.php'); mysql_connection_select(DATABASE); $rectypeID = @$_REQUEST['rty_id']; $mask = @$_REQUEST['mask']; if (array_key_exists("check", @$_REQUEST)) { if ($_REQUEST["check"] == 2) { //get coded mask $res = titlemask_make($mask, $rectypeID, 1, null, _ERR_REP_MSG); print is_array($res) ? $res[0] : $res; } else { if ($_REQUEST["check"] == 3) { //get human readable mask $res = titlemask_make($mask, $rectypeID, 2, null, _ERR_REP_MSG); print is_array($res) ? $res[0] : $res; } else { ///verify text title mask $check = check_title_mask2($mask, $rectypeID, true); if (!empty($check)) { print $check; } else { print ""; } } } } else { $recID = @$_REQUEST['rec_id']; $res = titlemask_value($mask, $recID); //."<br><br>".fill_title_mask_old($mask, $recID, $rectypeID);
function makeTitleMaskHumanReadable($fields, $rtID) { $cols = getRectypeColNames(); $ind1 = array_search('rty_TitleMask', $cols); $ind2 = array_search('rty_CanonicalTitleMask', $cols); //$ind2 = array_search('rty_Type', $cols); if ($ind2) { $fields[$ind2] = $fields[$ind1]; //keep canonical } $fields[$ind1] = titlemask_make($fields[$ind1], $rtID, 2, null, _ERR_REP_SILENT); return $fields; }
function generateSchema($projname, $rt_toexport, $rt_geoenabled) { global $rtStructs, $dtStructs, $dtTerms, $ind_descr, $supported; $hasMapTab = @$_REQUEST['mainmt'] == "1"; $hasControlTracklog = @$_REQUEST['ct4'] == "1"; $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <dataSchema />'); $root->addAttribute('name', DATABASE); $root->addAttribute('preparer', "Heurist user: "******"rst_FilteredJsonTermIDTree"]; $int_rt_termtree_dis = $rtStructs['typedefs']['dtFieldNamesToIndex']["dty_TermIDTreeNonSelectableIDs"]; $int_rt_dt_type = $rtStructs['typedefs']['dtFieldNamesToIndex']["dty_Type"]; $int_rt_disp_name = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_DisplayName"]; $int_rt_dt_descrip = $rtStructs['typedefs']['dtFieldNamesToIndex']['rst_DisplayHelpText']; $int_dt_ccode = $dtStructs['typedefs']['fieldNamesToIndex']['dty_ConceptID']; $idx_rst_pointers = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_PtrFilteredIDs"]; $rectyps = is_array($rt_toexport) ? $rt_toexport : explode(",", $rt_toexport); ///create RelationshipElement if there are 1 or more record types to export if (count($rectyps) > 0) { //ARTEM remove noise $reltypes = array(); //find relmarker fields foreach ($rectyps as $rt) { $rst_fields = $rtStructs['typedefs'][$rt]['dtFields']; if (!$rst_fields) { /*****DEBUG****/ //error_log("No details defined for RT#".$rt); continue; } foreach ($rst_fields as $dtid => $detail) { $rst_dt_type = $detail[$int_rt_dt_type]; if ($rst_dt_type == "relmarker") { //find all $termTree = $detail[$int_rt_termtree]; $disableTerms = $detail[$int_rt_termtree_dis]; $temp = preg_replace("/[\\[\\]\"]/", "", $disableTerms); $disableTerms = explode(",", $temp); //convert to tree $list = getTermsPlainList($rst_dt_type, $termTree, $disableTerms); $reltypes = array_merge($reltypes, $list); } else { if ($rst_dt_type == "resource") { $dt_pointers = $detail[$idx_rst_pointers]; $dt_pointers = explode(",", $dt_pointers); if (count($dt_pointers) > 0) { //ignore unconstrained $dtdisplayname = $detail[$int_rt_disp_name]; // the display name for this field $dtdisplaynamex = getProperName($dtdisplayname, $rt, $dtid); if (!@$reltypes["has" . $dtdisplaynamex]) { array_push($reltypes, "has" . $dtdisplaynamex); } } } } } //for detals } //for rectypes if (count($reltypes) > 0) { $reltypes = array_unique($reltypes); $termLookup = $dtTerms['termsByDomainLookup']['relation']; // only select relationship terms $ind_ccode = $dtTerms['fieldNamesToIndex']['trm_ConceptID']; $ind_tcode = $dtTerms['fieldNamesToIndex']['trm_Code']; $ind_tdescr = $dtTerms['fieldNamesToIndex']['trm_Description']; addComment($root, 'In Heurist, relationships are stored in a single relationship record type and ' + 'different types of relationship are distinguished by the relationship type field (attribute) whose ' + 'values can be organised hierarchichally. In FAIMS, each type of relationship is a separate record type, ' + 'organised into three classes - bidirectional, container and hierarchy'); foreach ($reltypes as $termid) { if (is_numeric($termid)) { //reltype $term = @$termLookup[$termid]; if (!$term) { continue; } $termCode = $term[$ind_tcode]; if (!$termCode) { $termCode = ""; } $termCcode = $term[$ind_ccode]; //concept code if (!$termCcode || strpos($termCcode, '-') === false) { $termCcode = intval(HEURIST_DBID) . '-' . $termid; } $termName = getResStrNoA16n(getFullTermName($term, 'relation')); $termDesc = prepareText($term[$ind_descr] ? $term[$ind_descr] : ""); } else { //resource-pointer $termCode = ""; $termCcode = ""; $termName = $termid; $termDesc = prepareText("Heurist pointer field: Directional relationship between the entity being described and a target entity"); } $rel = $root->addChild('RelationshipElement'); $rel->addAttribute('name', $termName); // required $rel->addAttribute('type', 'bidirectional'); $rel->addAttribute('HeuristID', $termCcode); // ignored by FAIMS oct 2013 $rel->addAttribute('StandardCode', $termCode); // ignored by FAIMS oct 2013 // getFullTermName gets a dash-separate hieerachy //$rel->addAttribute('pictureURL', ''); //$rel->addAttribute('semanticMapURL', ''); $rel->description = $termDesc; } } /* // // old version - all reltypes // $termLookup = $dtTerms['termsByDomainLookup']['relation']; // only select relationship terms $ind_ccode = $dtTerms['fieldNamesToIndex']['trm_ConceptID']; $ind_tcode = $dtTerms['fieldNamesToIndex']['trm_Code']; addComment($root, 'In Heurist, relationships are stored in a single relationship record type and different types of relationship are distinguished by the relationship type field (attribute) whose values can be organised hierarchichally. In FAIMS, each type of relationship is a separate record type, organised into three classes - bidirectional, container and hierarchy'); foreach ($termLookup as $termid=>$term) { if($term[$ind_parentid]>0){ $termCcode = @$termLookup[$termid][$ind_ccode]; //concept code $termCode = @$termLookup[$termid][$ind_tcode]; if(!$termCode){ $termCode = ""; } if(strpos($termCcode,'-')===false) { // check to see if registered database, insert 0 if not $termCcode = '0-'.$termid; // TODO: Artem, this shoudl be using original concept code NOT the internal code } $rel = $root->addChild('RelationshipElement'); $rel->addAttribute('name',getResStrNoA16n(getFullTermName($term, 'relation'))); // required $rel->addAttribute('type', 'bidirectional'); $rel->addAttribute('HeuristID', $termCcode); // ignored by FAIMS oct 2013 $rel->addAttribute('StandardCode', $termCode); // ignored by FAIMS oct 2013 // getFullTermName gets a dash-separate hieerachy //$rel->addAttribute('pictureURL', ''); //$rel->addAttribute('semanticMapURL', ''); // Artem, why are you adding a dash at the start of the descriptions if they exist, and leaving them null if they don't?? // I think you meant to do it the other way round (I've changed it) but this is horrible! $rel->description = prepareText( $term[$ind_descr]?$term[$ind_descr]:"-" ); //$rel->description = prepareText($termid."-".$term[$ind_label].($term[$ind_descr]?"-".$term[$ind_descr]:"")); } } */ addComment($root, 'Archaeological elements correspond with Heurist record types'); addComment($root, 'Properties correspond with Heurist base field types for this record type'); } // Output specifications for each ArchEnt (Record type in Heurist) foreach ($rectyps as $rt) { $rt_descr = $rtStructs['typedefs'][$rt]['commonFields'][$ind_rt_description]; //ARTEM print $rtStructs['names'][$rt]." desc=".$rt_descr; addComment($root, mb_strtoupper($rtStructs['names'][$rt])); $arch_element = $root->addChild('ArchaeologicalElement'); $arch_element->addAttribute('name', prepareText($rtStructs['names'][$rt])); $arch_element->description = prepareText($rt_descr); $titlemask = $rtStructs['typedefs'][$rt]['commonFields'][$ind_rt_titlemask]; $titlemask_canonical = $rtStructs['typedefs'][$rt]['commonFields'][$ind_rt_titlemask_canonical]; //backward capability - make sure that titlemask is canonical ie. uses internal codes not field names $titlemask = titlemask_make($titlemask, $rt, 1, null, _ERR_REP_SILENT); $has_identifier = false; $details = $rtStructs['typedefs'][$rt]['dtFields']; if (!$details) { /*****DEBUG****/ //error_log("1. No details defined for RT#".$rt); continue; } //important! to form proper record title we need to order properties in scheme in order they apper in title mask $dt_order = array(); $titlemask_rest = $titlemask; $offset = 0; $data = preg_match_all('/\\[([^\\"]*?)\\]/', $titlemask, $matches); //foreach $matches as if (count($matches) > 0) { for ($idx = 0; $idx < count($matches[1]); $idx++) { $entry = $matches[1][$idx]; //find detail in structure by concept code foreach ($details as $dtid => $detail) { $dt_type = $detail[$int_rt_dt_type]; if (!in_array($dt_type, $supported)) { continue; } $det = $dtStructs['typedefs'][$dtid]['commonFields']; $ccode = $det[$int_dt_ccode]; if ($ccode != '' && ($ccode == $entry || strpos($entry, $ccode . '.') !== false)) { $detail['isIdentifier'] = true; //get piece to next entry if ($idx + 1 < count($matches[0])) { $pos = strpos($titlemask, $matches[0][$idx + 1], $offset); $formatStr = substr($titlemask, $offset, $pos - $offset); $offset = $pos; } else { $formatStr = substr($titlemask, $offset); } if ($dt_type == 'enum' || $dt_type == 'relationtype') { $faimsmagic = '{{if $1 then "$1" }}'; } else { $faimsmagic = '{{if $2 then "$2" }}'; } //replace entry to faims magic $formatStr = str_replace($matches[0][$idx], $faimsmagic, $formatStr); $detail['formatString'] = $formatStr; $rtStructs['typedefs'][$rt]['dtFields'][$dtid]['isIdentifier'] = true; //to use later in ui_scheme $dt_order[$dtid] = $detail; break; } } } } // Each ArchEnt in FAIMS has to have at least one attribute (field) marked as an identifier if (count($dt_order) == 0) { addComment($root, 'ERROR!!!!! This ArchaeologicalEntity does not have identifiers!!! Verify TitleMask in Heurist recordtype!'); continue; } //add rest details foreach ($details as $dtid => $detail) { if (!@$dt_order[$dtid]) { $dt_order[$dtid] = $detail; } } // Loop through the fields (details) foreach ($dt_order as $dtid => $detail) { $dt_type = $detail[$int_rt_dt_type]; if (!in_array($dt_type, $supported)) { continue; } if ($dt_type == "resource") { $dt_pointers = $detail[$idx_rst_pointers]; $dt_pointers = explode(",", $dt_pointers); if (count($dt_pointers) < 1) { //ignore unconstrained continue; } } $property = $arch_element->addChild('property'); $property->addAttribute('name', prepareText($detail[$int_rt_disp_name])); $property->addAttribute('type', $dt_type); if ($detail[$int_rt_dt_descrip]) { $property->addChild('description', prepareText($detail[$int_rt_dt_descrip])); } if ($dt_type == "file") { $property->addAttribute('file', 'true'); $dtdisplayname = $detail[$int_rt_disp_name]; $ftype = detectFileType($dtdisplayname); $filetype = $ftype[1]; if ($filetype == 'camera') { //sync for camera only $property->addAttribute('thumbnail', 'true'); $property->addAttribute('sync', 'true'); } } /*$det = $dtStructs['typedefs'][$dtid]['commonFields']; $ccode = $det[$int_dt_ccode]; $is_in_titlemask = (!( strpos($titlemask, ".".$ccode."]")===false && strpos($titlemask, "[".$ccode."]")===false )) ; if($is_in_titlemask){*/ if (@$detail['isIdentifier']) { $property->addAttribute('isIdentifier', 'true'); if (@$detail['formatString']) { addCdata('formatString', $detail['formatString'], $property); } } if ($dt_type == 'enum' || $dt_type == 'relationtype') { $terms = $detail[$int_rt_termtree]; //convert to tree $cnt = getTermsTree($property, $dt_type, $terms); $is_hierarchy = isTermsHierarchical($dt_type, $terms); $rtStructs['typedefs'][$rt]['dtFields'][$dtid]['termdepth'] = $cnt; $rtStructs['typedefs'][$rt]['dtFields'][$dtid]['is_hierarchy'] = $is_hierarchy; } } //for if (in_array($rt, $rt_geoenabled)) { $property = $arch_element->addChild('property'); $property->addAttribute('name', 'Latitude'); $property->addAttribute('type', 'float'); $property = $arch_element->addChild('property'); $property->addAttribute('name', 'Longitude'); $property->addAttribute('type', 'float'); $property = $arch_element->addChild('property'); $property->addAttribute('name', 'Northing'); $property->addAttribute('type', 'float'); $property = $arch_element->addChild('property'); $property->addAttribute('name', 'Easting'); $property->addAttribute('type', 'float'); } } //foreach recordtype //specila entity for tracklog if (false && $hasControlTracklog) { addComment($root, mb_strtoupper("GPS TRACK")); $gps_track = new SimpleXMLElement(' <ArchaeologicalElement name="gps_track"> <description> A unit is a portion of trench described by this record.. </description> <property type="integer" name="gps_user" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="time" name="gps_timestamp" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="text" name="gps_longitude" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="text" name="gps_latitude" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="float" name="gps_heading" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="float" name="gps_accuracy" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> <property type="text" name="gps_type" minCardinality="1" maxCardinality="1" isIdentifier="true"> </property> </ArchaeologicalElement>'); xml_adopt($root, $gps_track); } $out = prepareXml($root); return $out; }
/** * Execute titlemask - replace tags with values * * @param mixed $mask * @param mixed $rec_id */ function titlemask_value($mask, $rec_id) { $rec_value = _titlemask__get_record_value($rec_id, true); if ($rec_value) { $rt = $rec_value['rec_RecTypeID']; return titlemask_make($mask, $rt, 0, $rec_id, _ERR_REP_WARN); } else { return "Title mask not generated. Record " . $rec_id . " not found"; } }
function checkRectypeMask($rtID, $rtName, $mask, $coMask, $recID, $mode) { global $mode; if (!@$mask && @$rtID) { $mask = mysql__select_array("defRecTypes", "rty_TitleMask", "rty_ID={$rtID}"); $mask = $mask[0]; } if ($mode > 0 || !$recID) { echo "<h3><b> {$rtID} : <i>{$rtName}</i></b> <br/> </h3>"; if ($mask == null || trim($mask) == "") { $res = array(); $res[0] = "Title mask is not defined"; } else { $res = titlemask_make($mask, $rtID, 2, null, _ERR_REP_MSG); //get human readable } echo "<div class='resultsRow'><div class='statusCell " . (is_array($res) ? "invalid'>in" : "valid'>") . "valid</div>"; echo "<div class='maskCell'>Mask: <i>{$mask}</i></div>"; if (is_array($res)) { echo "<div class='errorCell'><b>< < < < < " . $res[0] . "</b></div>"; } else { if ($mask == "") { echo "<div class='errorCell'><b>< < < < < EMPTY TITLE MASK</b></div>"; } else { if (strcasecmp($res, $mask) != 0) { echo "<div><br/> Decoded Mask: {$res}</div>"; } } } echo "</div>"; echo "\n"; } else { echo "checking title mask {$mask} for record type {$rtID} and record {$recID} <br/>"; echo fill_title_mask($mask, $recID, $rtID); } }