Skip to content

Commit

Permalink
Merge pull request #52 from BioKIC/master
Browse files Browse the repository at this point in the history
Merge BioKIC/Symbiota-light developments into CCH2 code repository
  • Loading branch information
egbot authored May 19, 2021
2 parents 49e7696 + aad5681 commit 84f6298
Show file tree
Hide file tree
Showing 44 changed files with 781 additions and 2,880 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ something far greater than a single entity is capable of doing on their own.

More information about this project can be accessed through:

(http://symbiota.org)
(https://symbiota.org)


## ACKNOWLEDGEMENTS
Expand Down
1 change: 0 additions & 1 deletion agents/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function pageheader($name) {
<meta name="keywords" content='. $spDisplay .' />
<link href="../css/base.css?ver=<?php echo $CSS_VERSION; ?>" type="text/css" rel="stylesheet" />
<link href="../css/main.css'.(isset($CSS_VERSION_LOCAL)?'?ver='.$CSS_VERSION_LOCAL:'').'" type="text/css" rel="stylesheet" />
<link href="../css/speciesprofilebase.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>';
// include_once($SERVER_ROOT.'/includes/googleanalytics.php');
Expand Down
4 changes: 3 additions & 1 deletion classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,8 @@ private function writeOccurrenceFile(){
$dwcOccurManager = new DwcArchiverOccurrence($this->conn);
$dwcOccurManager->setSchemaType($this->schemaType);
$dwcOccurManager->setExtended($this->extended);
$dwcOccurManager->setHarvestExsiccatae();
$dwcOccurManager->setIncludeExsiccatae();
$dwcOccurManager->setIncludeAssociatedSequences();
$dwcOccurManager->setIncludePaleo($this->hasPaleo);
if(!$this->occurrenceFieldArr) $this->occurrenceFieldArr = $dwcOccurManager->getOccurrenceArr($this->schemaType, $this->extended);
//Output records
Expand Down Expand Up @@ -1668,6 +1669,7 @@ private function writeOccurrenceFile(){
$r['occurrenceRemarks'] = $exsStr;
}
if($assocOccurStr = $dwcOccurManager->getAssociationStr($r['occid'])) $r['t_associatedOccurrences'] = $assocOccurStr;
if($assocSeqStr = $dwcOccurManager->getAssociatedSequencesStr($r['occid'])) $r['t_associatedSequences'] = $assocSeqStr;
if($assocTaxa = $dwcOccurManager->getAssocTaxa($r['occid'])) $r['associatedTaxa'] = $assocTaxa;
//$dwcOccurManager->appendUpperTaxonomy($r);
$dwcOccurManager->appendUpperTaxonomy2($r);
Expand Down
69 changes: 50 additions & 19 deletions classes/DwcArchiverOccurrence.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class DwcArchiverOccurrence{
private $schemaType;
private $extended = false;
private $includePaleo = false;
private $harvestExsiccatae = false;
private $includeExsiccatae = false;
private $includeAssocSeq = false;
private $relationshipArr;
private $upperTaxonomy = array();
private $taxonRankArr = array();
Expand Down Expand Up @@ -124,6 +125,8 @@ public function getOccurrenceArr(){
$this->occurDefArr['fields']['dynamicProperties'] = 'o.dynamicProperties';
$this->occurDefArr['terms']['associatedOccurrences'] = 'http://rs.tdwg.org/dwc/terms/associatedOccurrences';
$this->occurDefArr['fields']['associatedOccurrences'] = '';
$this->occurDefArr['terms']['associatedSequences'] = 'http://rs.tdwg.org/dwc/terms/associatedSequences';
$this->occurDefArr['fields']['associatedSequences'] = '';
$this->occurDefArr['terms']['associatedTaxa'] = 'http://rs.tdwg.org/dwc/terms/associatedTaxa';
$this->occurDefArr['fields']['associatedTaxa'] = 'o.associatedTaxa';
$this->occurDefArr['terms']['reproductiveCondition'] = 'http://rs.tdwg.org/dwc/terms/reproductiveCondition';
Expand Down Expand Up @@ -348,7 +351,7 @@ public function getSqlOccurrences($fieldArr, $fullSql = true){
//Special functions for appending additional data
public function getAdditionalCatalogNumberStr($occid){
$retStr = '';
if($occid){
if(is_numeric($occid)){
$sql = 'SELECT GROUP_CONCAT(CONCAT_WS(": ",identifierName, identifierValue) SEPARATOR "; ") as idStr FROM omoccuridentifiers WHERE occid = '.$occid;
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
Expand All @@ -359,35 +362,37 @@ public function getAdditionalCatalogNumberStr($occid){
return $retStr;
}

public function setHarvestExsiccatae(){
public function setIncludeExsiccatae(){
$sql = 'SELECT occid FROM omexsiccatiocclink LIMIT 1';
$rs = $this->conn->query($sql);
if($rs->num_rows) $this->harvestExsiccatae = true;
if($rs->num_rows) $this->includeExsiccatae = true;
$rs->free();
}

public function getExsiccateStr($occid){
$retStr = '';
$sql = 'SELECT t.title, t.abbreviation, t.editor, t.exsrange, n.exsnumber, l.notes '.
'FROM omexsiccatiocclink l INNER JOIN omexsiccatinumbers n ON l.omenid = n.omenid '.
'INNER JOIN omexsiccatititles t ON n.ometid = t.ometid '.
'WHERE l.occid = '.$occid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retStr = $r->title;
if($r->abbreviation) $retStr .= ' ['.$r->abbreviation.']';
if($r->exsrange) $retStr .= ', '.$r->exsrange;
if($r->editor) $retStr .= ', '.$r->editor;
$retStr .= ', exs #: '.$r->exsnumber;
if($r->notes) $retStr .= ' ('.$r->notes.')';
if($this->includeExsiccatae && is_numeric($occid)){
$sql = 'SELECT t.title, t.abbreviation, t.editor, t.exsrange, n.exsnumber, l.notes '.
'FROM omexsiccatiocclink l INNER JOIN omexsiccatinumbers n ON l.omenid = n.omenid '.
'INNER JOIN omexsiccatititles t ON n.ometid = t.ometid '.
'WHERE l.occid = '.$occid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retStr = $r->title;
if($r->abbreviation) $retStr .= ' ['.$r->abbreviation.']';
if($r->exsrange) $retStr .= ', '.$r->exsrange;
if($r->editor) $retStr .= ', '.$r->editor;
$retStr .= ', exs #: '.$r->exsnumber;
if($r->notes) $retStr .= ' ('.$r->notes.')';
}
$rs->free();
}
$rs->free();
return $retStr;
}

public function getAssociationStr($occid){
$retStr = '';
if($occid){
if(is_numeric($occid)){
$sql = 'SELECT assocID, occid, occidAssociate, relationship, subType, resourceUrl, identifier FROM omoccurassociations WHERE (occid = '.$occid.' OR occidAssociate = '.$occid.') AND verbatimSciname IS NULL ';
$rs = $this->conn->query($sql);
if($rs){
Expand Down Expand Up @@ -436,9 +441,35 @@ public function getAssociationStr($occid){
return trim($retStr,' |');
}

public function setIncludeAssociatedSequences(){
$sql = 'SELECT occid FROM omoccurgenetic LIMIT 1';
$rs = $this->conn->query($sql);
if($rs->num_rows) $this->includeAssocSeq = true;
$rs->free();
}

public function getAssociatedSequencesStr($occid){
$retStr = '';
if(is_numeric($occid)){
$sql = 'SELECT identifier, resourceName, title, locus, resourceUrl FROM omoccurgenetic WHERE occid = '.$occid;
$rs = $this->conn->query($sql);
if($rs){
while($r = $rs->fetch_object()){
$retStr .= '|'.$r->resourceName.', ';
if($r->title) $retStr .= $r->title.', ';
if($r->identifier) $retStr .= $r->identifier.', ';
if($r->locus) $retStr .= $r->locus.', ';
$retStr .= $r->resourceUrl;
}
$rs->free();
}
}
return trim($retStr,' |,');
}

public function getAssocTaxa($occid){
$retStr = '';
if($occid){
if(is_numeric($occid)){
$sql = 'SELECT assocID, relationship, subType, verbatimSciname FROM omoccurassociations WHERE occid = '.$occid.' AND verbatimSciname IS NOT NULL ';
$rs = $this->conn->query($sql);
if($rs){
Expand Down
1 change: 0 additions & 1 deletion classes/GlossaryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,6 @@ public function getTaxaList($queryString, $type){
'WHERE (t.SciName LIKE "'.$queryString.'%" OR v.VernacularName LIKE "'.$queryString.'%") AND t.RankId < 185 AND ts.taxauthid = 1 '.
'ORDER BY t.SciName, v.sortsequence LIMIT 20 ';
$rs = $this->conn->query($sql);
$taxa = array();
if($type == 'single'){
while ($row = $rs->fetch_object()) {
$sciName = $row->SciName;
Expand Down
2 changes: 0 additions & 2 deletions classes/GlossaryUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function loadFile($fieldMap,$languageArr,$tidStr,$batchSources){
$this->conn->query("TRUNCATE TABLE uploadglossary");
$this->conn->query("OPTIMIZE TABLE uploadglossary");
$fh = fopen($this->uploadTargetPath.$this->uploadFileName,'r') or die("Can't open file");
$headerArr = fgetcsv($fh);
$newTermColumn = false;
foreach($languageArr as $lang){
foreach($fieldMap as $csvField => $field){
Expand Down Expand Up @@ -200,7 +199,6 @@ public function cleanUpload($tidStr){
}

public function analysisUpload(){
$retArr = array();
//Get total number
$sql1 = 'SELECT count(*) as cnt FROM uploadglossary';
$rs1 = $this->conn->query($sql1);
Expand Down
2 changes: 1 addition & 1 deletion classes/OccurrenceDuplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getClusterArr($occid){
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_object()){
$retArr[$r->duplicateid]['o'][$r->occid] = array('instcode' => $r->institutioncode, 'collcode' => $r->collectioncode,
'collname' => $r->collectionname, 'catnum' => $r->catalognumber, 'occurrenceid' => $r->occurrenceid, 'sciname' => $r->sciname, 'author' => $r->scientificnameauthorship,
'collname' => $r->collectionname, 'catnum' => $r->catalognumber, 'occurrenceid' => $r->occurrenceid, 'sciname' => $r->sciname, 'author' => $r->scientificnameauthorship,
'identifiedby' => $r->identifiedby, 'dateidentified' => $r->dateidentified, 'recordedby' => $r->recordedby,
'recordnumber' => $r->recordnumber, 'eventdate' => $r->eventdate, 'notes' => $r->notes, 'tnurl' => $r->thumbnailurl,
'url' => $r->url);
Expand Down
1 change: 0 additions & 1 deletion classes/OccurrenceEditReview.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
include_once($SERVER_ROOT.'/config/dbconnection.php');
include_once($SERVER_ROOT.'/classes/Manager.php');

class OccurrenceEditReview extends Manager{
Expand Down
4 changes: 1 addition & 3 deletions classes/OccurrenceEditorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,6 @@ protected function setOccurArr($start = 0, $limit = 0){
}
if($sqlFrag){
$sql = 'SELECT DISTINCT o.occid, o.collid, o.'.implode(',o.',$this->occFieldArr).' FROM omoccurrences o '.$sqlFrag;
//$sql = 'SELECT o.occid, o.collid, o.'.implode(',o.',$this->occFieldArr).' FROM omoccurrences o '.$sqlFrag;
//echo "<div>".$sql."</div>";
$previousOccid = 0;
$rs = $this->conn->query($sql);
$rsCnt = 0;
Expand All @@ -672,7 +670,7 @@ protected function setOccurArr($start = 0, $limit = 0){
elseif($this->occid == $row['occid']){
//Is target specimen
$retArr[$row['occid']] = array_change_key_case($row);
if($this->collMap['colltype'] == 'General Observations' && $row->observeruid == $GLOBALS['SYMB_UID']) $this->isPersonalManagement = true;
if($this->collMap['colltype'] == 'General Observations' && $row['observeruid'] == $GLOBALS['SYMB_UID']) $this->isPersonalManagement = true;
}
elseif(is_numeric($localIndex) && $localIndex == $rsCnt){
$retArr[$row['occid']] = array_change_key_case($row);
Expand Down
35 changes: 35 additions & 0 deletions classes/OccurrenceEditorMaterialSample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
include_once($SERVER_ROOT.'/classes/Manager.php');

class OccurrenceEditorMaterialSample extends Manager{

private $occid;

function __construct(){
parent::__construct(null,'write');
}

function __destruct(){
parent::__destruct();
}

public function getMaterialSampleArr(){
$retArr = array();
$sql = 'SELECT msID, materialSampleType, concentration, concentrationUnit, concentrationMethod, ratioOfAbsorbance260_230, ratioOfAbsorbance260_280, volume, volumeUnit, '.
'weight, weightUnit, weightMethod, purificationMethod, quality, qualityRemarks, qualityCheckDate, sampleSize, sieving, dnaHybridization, dnaMeltingPoint, '.
'estimatedSize, poolDnaExtracts, sampleDesignation, initialTimestamp '.
'FROM ommaterialsample '.
'WHERE occid = '.$this->occid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_assoc()){
$retArr[$r['msID']] = $r;
}
$rs->free();
return $retArr;
}

public function setOccid($id){
if(is_numeric($id)) $this->occid = $id;
}
}
?>
33 changes: 29 additions & 4 deletions classes/OccurrenceIndividual.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
include_once('Manager.php');
include_once('OccurrenceDuplicate.php');
include_once('OccurrenceAccessStats.php');

class OccurrenceIndividual extends Manager{
Expand Down Expand Up @@ -357,9 +356,35 @@ private function setReferences(){
}

public function getDuplicateArr(){
$dupManager = new OccurrenceDuplicate();
$retArr = $dupManager->getClusterArr($this->occid);
unset($retArr[$this->occid]);
$retArr = array();
$sqlBase = 'SELECT o.occid, c.institutioncode AS instcode, c.collectioncode AS collcode, c.collectionname AS collname, o.catalognumber, o.occurrenceid, o.sciname, '.
'o.scientificnameauthorship AS author, o.identifiedby, o.dateidentified, o.recordedby, o.recordnumber, o.eventdate, IFNULL(i.thumbnailurl, i.url) AS url ';
//Get exsiccati duplicates
if(isset($this->occArr['exs'])){
$sql = $sqlBase.'FROM omexsiccatiocclink l INNER JOIN omexsiccatiocclink l2 ON l.omenid = l2.omenid '.
'INNER JOIN omoccurrences o ON l2.occid = o.occid '.
'INNER JOIN omcollections c ON o.collid = c.collid '.
'LEFT JOIN images i ON o.occid = i.occid '.
'WHERE l.occid = '.$this->occid;
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_assoc()){
$retArr['exs'][$r['occid']] = array_change_key_case($r);
}
$rs->free();
}
}
//Get specimen duplicates
$sql = $sqlBase.'FROM omoccurduplicatelink d INNER JOIN omoccurduplicatelink d2 ON d.duplicateid = d2.duplicateid '.
'INNER JOIN omoccurrences o ON d2.occid = o.occid '.
'INNER JOIN omcollections c ON o.collid = c.collid '.
'LEFT JOIN images i ON o.occid = i.occid '.
'WHERE (d.occid = '.$this->occid.') AND (d.occid != d2.occid) ';
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_assoc()){
if(!isset($retArr['exs'][$r['occid']])) $retArr['dupe'][$r['occid']] = array_change_key_case($r);
}
$rs->free();
}
return $retArr;
}

Expand Down
20 changes: 11 additions & 9 deletions classes/OccurrenceLoans.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,10 @@ public function editSpecimen($reqArr){
$status = false;
if(!array_key_exists('occid',$reqArr)) return;
$occidArr = $reqArr['occid'];
$applyTask = $reqArr['applytask'];
$loanid = $reqArr['loanid'];
if(is_numeric($loanid)){
if($occidArr){
if($applyTask == 'delete'){
if($reqArr['applytask'] == 'delete'){
$sql = 'DELETE FROM omoccurloanslink WHERE loanid = '.$loanid.' AND (occid IN('.implode(',',$occidArr).')) ';
if($this->conn->query($sql)) $status = true;
else $this->errorMessage = 'ERROR removing specimen from loan: '.$this->conn->error;
Expand All @@ -611,24 +610,27 @@ public function editSpecimen($reqArr){
return $status;
}

public function getSpecimenNotes($loanId, $occid){
$noteStr = '';
public function getSpecimenDetails($loanId, $occid){
$retArr = array();
if(is_numeric($loanId) && is_numeric($occid)){
$sql = 'SELECT notes FROM omoccurloanslink WHERE loanid = '.$loanId.' AND occid = '.$occid;
$sql = 'SELECT DATE_FORMAT(returndate, "%Y-%m-%dT%H:%i") AS returndate, notes FROM omoccurloanslink WHERE loanid = '.$loanId.' AND occid = '.$occid;
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_object()){
$noteStr = $r->notes;
$retArr['returnDate'] = $r->returndate;
$retArr['notes'] = $r->notes;
}
$rs->free();
}
}
return $noteStr;
return $retArr;
}

public function editSpecimenNotes($loanId, $occid, $noteStr){
public function editSpecimenDetails($loanId, $occid, $returnDate, $noteStr){
$status = false;
if(is_numeric($loanId) && is_numeric($occid)){
$sql = 'UPDATE omoccurloanslink SET notes = '.($noteStr?'"'.$this->cleanInStr($noteStr).'"':'NULL').' WHERE (loanid = '.$loanId.') AND (occid = '.$occid.')';
$sql = 'UPDATE omoccurloanslink '.
'SET returnDate = '.($returnDate?'"'.$this->cleanInStr($returnDate).'"':'NULL').', notes = '.($noteStr?'"'.$this->cleanInStr($noteStr).'"':'NULL').' '.
'WHERE (loanid = '.$loanId.') AND (occid = '.$occid.')';
if($this->conn->query($sql)) $status = true;
else $this->errorMessage = 'ERROR updating specimen notes: '.$this->conn->error;
}
Expand Down
6 changes: 4 additions & 2 deletions classes/OccurrenceMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,16 @@ public function updateCollectionStats($collid, $full = false){
$rs->free();

if($this->verbose) $this->outputMsg('Calculating genetic resources counts... ',1);
$sql = 'SELECT COUNT(CASE WHEN g.resourceurl LIKE "http://www.boldsystems%" THEN o.occid ELSE NULL END) AS boldcnt, '.
'COUNT(CASE WHEN g.resourceurl LIKE "http://www.ncbi%" THEN o.occid ELSE NULL END) AS gencnt '.
$sql = 'SELECT COUNT(CASE WHEN g.resourceurl LIKE "%boldsystems%" THEN o.occid ELSE NULL END) AS boldcnt, '.
'COUNT(CASE WHEN g.resourceurl LIKE "%ncbi%" THEN o.occid ELSE NULL END) AS gencnt, '.
'COUNT(CASE WHEN g.resourceurl NOT LIKE "%boldsystems%" AND g.resourceurl NOT LIKE "%ncbi%" THEN o.occid ELSE NULL END) AS geneticcnt '.
'FROM omoccurrences o INNER JOIN omoccurgenetic g ON o.occid = g.occid '.
'WHERE (o.collid IN('.$collid.')) ';
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$statsArr['boldcnt'] = $r->boldcnt;
$statsArr['gencnt'] = $r->gencnt;
$statsArr['geneticcnt'] = $r->geneticcnt;
}
$rs->free();

Expand Down
1 change: 1 addition & 0 deletions collections/cleaning/taxonomycleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<head>
<title><?php echo $DEFAULT_TITLE; ?> Occurrence Taxon Cleaner</title>
<?php
$activateJQuery = true;
include_once($SERVER_ROOT.'/includes/head.php');
?>
<script src="../../js/jquery-3.2.1.min.js?ver=3" type="text/javascript"></script>
Expand Down
Loading

0 comments on commit 84f6298

Please sign in to comment.