Skip to content

Commit

Permalink
Merge pull request #24 from BioKIC/master
Browse files Browse the repository at this point in the history
Synchronize with BioKIC/Symbiota developments
  • Loading branch information
egbot authored Nov 9, 2023
2 parents 874a3d5 + 5b8fe4b commit 61d7f0a
Show file tree
Hide file tree
Showing 90 changed files with 1,257 additions and 1,124 deletions.
2 changes: 2 additions & 0 deletions admin/schemamanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
$schemaManager->setPort($port);
$schemaManager->setUsername($username);
$schemaManager->installPatch();
$verHistory = $schemaManager->getVersionHistory();
$curentVersion = $schemaManager->getCurrentVersion();
}
?>
</fieldset>
Expand Down
6 changes: 1 addition & 5 deletions checklists/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,14 @@
if($clid) echo 'var clid = '.$clid.';'."\n";
echo 'var taxaCount = '.count($taxaArray).';'."\n";
?>
$( function() {
$( document ).tooltip();
} );

function changeImageSource(elem){
let f = document.optionform;
if(elem.id == "vi_voucher") f.voucherimages.value = "1";
else f.voucherimages.value = "0";
f.submit();
}
</script>
<script type="text/javascript" src="../js/symb/checklists.checklist.js?ver=3"></script>
<script type="text/javascript" src="../js/symb/checklists.checklist.js?ver=4"></script>
<style type="text/css">
<?php
if($printMode){
Expand Down
4 changes: 2 additions & 2 deletions checklists/rpc/searchsuggest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
include_once('../../config/symbini.php');
include_once($SERVER_ROOT.'/classes/ChecklistManager.php');
header("Content-Type: text/html; charset=".$CHARSET);
header('Content-Type: text/html; charset='.$CHARSET);

$clid = $_REQUEST['clid'];
$term = $_REQUEST['term'];
$deep = (isset($_REQUEST['deep'])?$_REQUEST['deep']:0);

$clManager = new ChecklistManager();
$retArr = $clManager->getTaxonSearch($term,$clid,$deep);
$retArr = $clManager->getTaxonSearch($term, $clid, $deep);
echo json_encode($retArr);
?>
4 changes: 2 additions & 2 deletions checklists/vamissingtaxa.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
ksort($missingArr);
foreach($missingArr as $sciname => $sArr){
foreach($sArr as $occid => $oArr){
$sciStr = $sciname;
if($sciStr != $oArr['o_sn']) $sciStr .= ' (syn: '.$oArr['o_sn'].')';
$sciStr = $oArr['o_sn'];
if(strtolower($sciname) != strtolower($oArr['o_sn'])) $sciStr .= ' (='.$sciname.')';
echo '<tr>';
echo '<td><input name="occids[]" type="checkbox" value="'.$occid.'-'.$oArr['tid'].'" /></td>';
echo '<td><a href="../taxa/index.php?taxon='.$oArr['tid'].'" target="_blank">'.$sciStr.'</a></td>';
Expand Down
7 changes: 4 additions & 3 deletions classes/ChecklistLoaderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public function uploadCsvList($thesId){
ob_flush();
flush();
while($valueArr = fgetcsv($fh)){
$sciNameStr = $this->cleanInStr($valueArr[$headerArr["sciname"]]);
//Remove UTF-8 NO-BREAK SPACE codepoints
$sciNameStr = str_replace(chr(194).chr(160), ' ', $valueArr[$headerArr['sciname']]);
$sciNameStr = $this->cleanInStr($sciNameStr);
if($sciNameStr){
$tid = 0;
$rankId = 0;
Expand All @@ -60,7 +62,7 @@ public function uploadCsvList($thesId){
'WHERE ts.taxauthid = 1 ';
}
$cleanSciName = $this->encodeString($sciNameArr['sciname']);
$sql .= 'AND (t.sciname IN("'.$sciNameStr.'"'.($cleanSciName?',"'.$cleanSciName.'"':'').'))';
$sql .= 'AND (t.sciname IN("'.$sciNameStr.'"'.($cleanSciName && $cleanSciName != $sciNameStr ?',"'.$cleanSciName.'"':'').'))';
$rs = $this->conn->query($sql);
if($rs){
while($row = $rs->fetch_object()){
Expand Down Expand Up @@ -106,7 +108,6 @@ public function uploadCsvList($thesId){
}

$sql = 'INSERT INTO fmchklsttaxalink (tid,clid'.$sqlInsert.') VALUES ('.$tid.', '.$this->clid.$sqlValues.')';
//echo $sql; exit;
if($this->conn->query($sql)){
$successCnt++;
}
Expand Down
10 changes: 7 additions & 3 deletions classes/ChecklistManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,16 @@ private function setImages(){
if($this->taxaList){
$matchedArr = array();
if($this->limitImagesToVouchers){
$clidStr = $this->clid;
if($this->childClidArr){
$clidStr .= ','.implode(',',array_keys($this->childClidArr));
}
$sql = 'SELECT i.tid, i.url, i.thumbnailurl, i.originalurl
FROM images i INNER JOIN omoccurrences o ON i.occid = o.occid
INNER JOIN fmvouchers v ON o.occid = v.occid
INNER JOIN fmchklsttaxalink cl ON v.clTaxaID = cl.clTaxaID
WHERE (cl.clid = 2) AND (i.tid IN('.implode(',',array_keys($this->taxaList)).'))';
WHERE (cl.clid = '.$clidStr.') AND (i.tid IN('.implode(',',array_keys($this->taxaList)).'))
ORDER BY i.sortOccurrence, i.sortSequence';
$matchedArr = $this->setImageSubset($sql);
}
if($missingArr = array_diff(array_keys($this->taxaList),$matchedArr)){
Expand All @@ -346,7 +351,7 @@ private function setImages(){
$matchedArr = $this->setImageSubset($sql);
if($missingArr = array_diff(array_keys($this->taxaList),$matchedArr)){
//Get children images
$sql = 'SELECT i2.tid, i.url, i.thumbnailurl FROM images i INNER JOIN '.
$sql = 'SELECT DISTINCT i2.tid, i.url, i.thumbnailurl FROM images i INNER JOIN '.
'(SELECT ts1.parenttid AS tid, SUBSTR(MIN(CONCAT(LPAD(i.sortsequence,6,"0"),i.imgid)),7) AS imgid '.
'FROM taxstatus ts1 INNER JOIN taxstatus ts2 ON ts1.tidaccepted = ts2.tidaccepted '.
'INNER JOIN images i ON ts2.tid = i.tid '.
Expand All @@ -361,7 +366,6 @@ private function setImages(){
private function setImageSubset($sql){
$matchTidArr = array();
if($this->taxaList){
//echo $sql;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
if(!in_array($r->tid,$matchTidArr)){
Expand Down
62 changes: 47 additions & 15 deletions classes/ChecklistVoucherAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function linkVouchers($occidArr){
return $statusCnt;
}

public function linkVoucher($taxa, $occid, $morphoSpecies=''){
public function linkVoucher($taxa, $occid, $morphoSpecies = '', $editorNotes = null, $notes = null){
$status = false;
if($this->voucherIsLinked($occid)){
$this->errorMessage = 'voucherAlreadyLinked';
Expand All @@ -364,23 +364,32 @@ public function linkVoucher($taxa, $occid, $morphoSpecies=''){
$clTaxaID = $this->getClTaxaID($taxa, $morphoSpecies);
if(!$clTaxaID) $clTaxaID = $this->insertChecklistTaxaLink($taxa);
if($clTaxaID){
$status = $this->insertVoucher($clTaxaID, $occid);
$status = $this->insertVoucher($clTaxaID, $occid, $editorNotes, $notes);
}
return $status;
}

public function linkTaxaVouchers($occidArr, $useCurrentTaxon = true, $linkVouchers = true){
$tidsUsed = array();
$tidMap = array();
foreach($occidArr as $v){
$vArr = explode('-',$v);
$tid = $vArr[1];
$occid = $vArr[0];
if(count($vArr) == 2 && is_numeric($occid) && is_numeric($tid)){
if($useCurrentTaxon) $tid = $this->getTidAccepted($tid);
if(!in_array($tid, $tidsUsed)){
//Add name to checklist
$clTaxaID = $this->insertChecklistTaxaLink($tid);
$tidsUsed[] = $tid;
if(count($vArr) == 2){
$tid = $vArr[1];
$occid = $vArr[0];
if(is_numeric($occid) && is_numeric($tid)){
$clTaxaID = 0;
if(isset($tidMap[$tid])) $clTaxaID = $tidMap[$tid];
else{
$clTaxaID = $this->getClTaxaID($tid);
if(!$clTaxaID){
if($useCurrentTaxon){
$tid = $this->getTidAccepted($tid);
}
//Add name to checklist
$clTaxaID = $this->insertChecklistTaxaLink($tid);
}
$tidMap[$tid] = $clTaxaID;
}
if($clTaxaID && $linkVouchers){
$this->insertVoucher($clTaxaID, $occid);
}
Expand Down Expand Up @@ -495,16 +504,39 @@ private function transferVouchers($target, $source){
return $status;
}

public function deleteVoucher($voucherID){
$status = false;
if(is_numeric($voucherID)){
$sql = 'DELETE FROM fmvouchers WHERE (voucherID = ?)';
if($stmt = $this->conn->prepare($sql)) {
$stmt->bind_param('i', $voucherID);
$stmt->execute();
if($stmt->affected_rows) $status = true;
elseif($stmt->error) $this->errorMessage = 'ERROR deleting vouchers: '.$stmt->error;
$stmt->close();
}
else $this->errorMessage = 'ERROR preparing statement for voucher deletion: '.$this->conn->error;
}
return $status;
}

//Misc support and data functions
protected function getClTaxaID($tid, $morphoSpecies = ''){
$clTaxaID = 0;
$resultTid = 0;
if(is_numeric($tid)){
$sql = 'SELECT clTaxaID FROM fmchklsttaxalink WHERE clid = ? AND tid = ? AND morphospecies = ?';
if($stmt = $this->conn->prepare($sql)) {
$sql = 'SELECT c.clTaxaID, c.tid
FROM fmchklsttaxalink c INNER JOIN taxstatus ts ON c.tid = ts.tid
INNER JOIN taxstatus ts2 ON ts.tidaccepted = ts2.tidaccepted
WHERE ts.taxAuthID = 1 AND ts2.taxAuthID = 1 AND c.clid = ? AND ts2.tid = ? AND c.morphospecies = ?';
if($stmt = $this->conn->prepare($sql)){
if($stmt->bind_param('iis', $this->clid, $tid, $morphoSpecies)){
$stmt->execute();
$stmt->bind_result($clTaxaID);
$stmt->fetch();
$stmt->bind_result($clTaxaID, $resultTid);
while($stmt->fetch()){
//If there are multiple accepted records, take preferrence to clTaxaID associated with the accepted taxon
if($tid == $resultTid) break;
}
$stmt->close();
}
else $this->errorMessage = 'ERROR binding params for getClTaxaID: '.$this->conn->error;
Expand Down
16 changes: 0 additions & 16 deletions classes/ChecklistVoucherManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,6 @@ private function addVoucherRecord($vOccId, $vNotes, $vEditNotes){
return false;
}

public function deleteVoucher($voucherID){
$status = false;
if(is_numeric($voucherID)){
$sql = 'DELETE FROM fmvouchers WHERE (voucherID = ?)';
if($stmt = $this->conn->prepare($sql)) {
$stmt->bind_param('i', $voucherID);
$stmt->execute();
if($stmt->affected_rows) $status = true;
elseif($stmt->error) $this->errorMessage = 'ERROR deleting vouchers: '.$stmt->error;
$stmt->close();
}
else $this->errorMessage = 'ERROR preparing statement for voucher deletion: '.$this->conn->error;
}
return $status;
}

//Setters and getters
public function setTid($t){
if(is_numeric($t)){
Expand Down
18 changes: 9 additions & 9 deletions classes/ChecklistVoucherReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public function getNewVouchers($startLimit = 500, $includeAll = 1){
if($this->clid){
if($sqlFrag = $this->getSqlFrag()){
if($includeAll == 1 || $includeAll == 2){
$sql = 'SELECT DISTINCT cl.clTaxaID, TRIM(CONCAT_WS(" ",t.sciname,cl.morphoSpecies)) AS clsciname, o.occid, c.institutioncode, c.collectioncode, o.catalognumber, '.
'o.tidinterpreted, o.sciname, o.recordedby, o.recordnumber, o.eventdate, CONCAT_WS("; ",o.country, o.stateprovince, o.county, o.locality) as locality '.
'FROM omoccurrences o LEFT JOIN omcollections c ON o.collid = c.collid '.
'INNER JOIN taxstatus ts ON o.tidinterpreted = ts.tid '.
'INNER JOIN fmchklsttaxalink cl ON ts.tidaccepted = cl.tid '.
'INNER JOIN taxa t ON cl.tid = t.tid ';
$sql = 'SELECT DISTINCT cl.clTaxaID, TRIM(CONCAT_WS(" ",t.sciname,cl.morphoSpecies)) AS clsciname, o.occid, c.institutioncode, c.collectioncode, o.catalognumber,
o.tidinterpreted, o.sciname, o.recordedby, o.recordnumber, o.eventdate, CONCAT_WS("; ",o.country, o.stateprovince, o.county, o.locality) as locality
FROM omoccurrences o LEFT JOIN omcollections c ON o.collid = c.collid
INNER JOIN taxstatus ts ON o.tidinterpreted = ts.tid
INNER JOIN taxstatus ts2 ON ts.tidaccepted = ts2.tidaccepted
INNER JOIN fmchklsttaxalink cl ON ts2.tid = cl.tid
INNER JOIN taxa t ON cl.tid = t.tid ';
$sql .= $this->getTableJoinFrag($sqlFrag);
$sql .= 'WHERE ('.$sqlFrag.') AND (cl.clid = '.$this->clid.') AND (ts.taxauthid = 1) ';
$sql .= 'WHERE ('.$sqlFrag.') AND (cl.clid = '.$this->clid.') AND (ts.taxauthid = 1) AND (ts2.taxauthid = 1) ';
if($includeAll == 1){
$idStr = $this->getVoucherTidStr('tid');
if($idStr) $sql .= 'AND cl.tid NOT IN('.$idStr.') ';
Expand All @@ -85,12 +86,11 @@ public function getNewVouchers($startLimit = 500, $includeAll = 1){
if($idStr) $sql .= 'AND o.occid NOT IN('.$idStr.') ';
}
$sql .= 'ORDER BY ts.family, o.sciname LIMIT '.$startLimit.', 1000';
//echo '<div>'.$sql.'</div>';
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retArr[$r->clTaxaID][$r->occid]['tid'] = $r->tidinterpreted;
$sciName = $r->clsciname;
if($r->clsciname <> $r->sciname) $sciName .= '<br/>specimen id: '.$r->sciname;
if($r->clsciname <> $r->sciname) $sciName .= '<br/>[specimen id: '.$r->sciname.']';
$retArr[$r->clTaxaID][$r->occid]['sciname'] = $sciName;
$collCode = '';
if(!$r->catalognumber || strpos($r->catalognumber, $r->institutioncode) === false){
Expand Down
19 changes: 9 additions & 10 deletions classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DwcArchiverCore extends Manager{
private $includeDets = 1;
private $includeImgs = 1;
private $includeAttributes = 0;
private $includeMaterialSample = 0; // 0 = off, 1 = on, 2 = active (activated within at least one collection)
private $includeMaterialSample = 0;
private $hasPaleo = false;
private $redactLocalities = 1;
private $rareReaderArr = array();
Expand Down Expand Up @@ -191,7 +191,6 @@ public function setCollArr($collTarget, $collType = ''){
if (isset($modArr['paleo']['status'])) $this->hasPaleo = true;
elseif (isset($modArr['matSample']['status'])){
$this->collArr[$r->collid]['matSample'] = 1;
$this->includeMaterialSample = 2;
}
}
}
Expand Down Expand Up @@ -1055,7 +1054,7 @@ private function writeMetaFile(){
}

//MaterialSample extension
if ($this->includeMaterialSample == 2 && isset($this->fieldArrMap['materialSample'])) {
if ($this->includeMaterialSample && isset($this->fieldArrMap['materialSample'])) {
$extElem3 = $newDoc->createElement('extension');
$extElem3->setAttribute('encoding', $this->charSetOut);
$extElem3->setAttribute('fieldsTerminatedBy', $this->delimiter);
Expand Down Expand Up @@ -1765,7 +1764,7 @@ private function writeOccurrenceFile(){

$batchOccidArr[] = $r['occid'];
if (count($batchOccidArr) > 1000) {
if ($this->includeMaterialSample == 2) $this->writeMaterialSampleData($materialSampleHandler, $batchOccidArr);
if ($this->includeMaterialSample) $this->writeMaterialSampleData($materialSampleHandler, $batchOccidArr);
if ($pubID && $portalManager) $portalManager->insertPortalOccurrences($pubID, $batchOccidArr);
unset($batchOccidArr);
$batchOccidArr = array();
Expand All @@ -1782,7 +1781,7 @@ private function writeOccurrenceFile(){
if ($batchOccidArr) {
if ($pubID && $portalManager) $portalManager->insertPortalOccurrences($pubID, $batchOccidArr);
}
if ($this->includeMaterialSample == 2){
if ($this->includeMaterialSample){
$this->writeMaterialSampleData($materialSampleHandler, $batchOccidArr);
$materialSampleHandler->__destruct();
}
Expand All @@ -1801,7 +1800,7 @@ private function writeOccurrenceFile(){
$this->logOrEcho($this->errorMessage);
}
$this->logOrEcho('Done! (' . date('h:i:s A') . ")\n");
if ($this->includeMaterialSample == 2) $this->logOrEcho('Material Sample extension file created (' . date('h:i:s A') . ')... ');
if ($this->includeMaterialSample) $this->logOrEcho('Material Sample extension file created (' . date('h:i:s A') . ')... ');
return $filePath;
}

Expand Down Expand Up @@ -2161,19 +2160,19 @@ public function setDelimiter($d){
}

public function setIncludeDets($includeDets){
$this->includeDets = $includeDets;
if($includeDets) $this->includeDets = true;
}

public function setIncludeImgs($includeImgs){
$this->includeImgs = $includeImgs;
if($includeImgs) $this->includeImgs = true;
}

public function setIncludeAttributes($include){
$this->includeAttributes = $include;
if($include) $this->includeAttributes = true;
}

public function setIncludeMaterialSample($include){
$this->includeMaterialSample = $include;
if($include) $this->includeMaterialSample = true;
}

public function hasAttributes(){
Expand Down
2 changes: 1 addition & 1 deletion classes/DwcArchiverOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function getOccurrenceArr(){
elseif($this->schemaType == 'coge'){
$targetArr = array('id','basisOfRecord','institutionCode','collectionCode','catalogNumber','occurrenceID','family','scientificName','scientificNameAuthorship',
'kingdom','phylum','class','order','genus','specificEpithet','infraSpecificEpithet','recordedBy','recordNumber','eventDate','year','month','day','fieldNumber',
'locationID','continent','waterBody','islandGroup','island','country','stateProvince','county','municipality',
'eventID', 'locationID','continent','waterBody','islandGroup','island','country','stateProvince','county','municipality',
'locality','localitySecurity','geodeticDatum','decimalLatitude','decimalLongitude','verbatimCoordinates',
'minimumElevationInMeters','maximumElevationInMeters','verbatimElevation','maximumDepthInMeters','minimumDepthInMeters','establishmentMeans',
'occurrenceRemarks','dateEntered','dateLastModified','recordID','references','collID');
Expand Down
Loading

0 comments on commit 61d7f0a

Please sign in to comment.