Skip to content

Commit

Permalink
Merge pull request #20 from bryo-lichen/master
Browse files Browse the repository at this point in the history
Merge BioKIC/Symbiota-light code developments into bryo-lichen code forks
  • Loading branch information
egbot authored Feb 10, 2021
2 parents 4c4c557 + be41b34 commit e555f42
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 45 deletions.
28 changes: 14 additions & 14 deletions checklists/dynamicchecklist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
//error_reporting(E_ALL);
include_once('../config/symbini.php');
include_once($SERVER_ROOT.'/classes/DynamicChecklistManager.php');
header("Content-Type: text/html; charset=".$CHARSET);
Expand All @@ -9,6 +8,7 @@
$radius = $_POST['radius'];
$radiusUnits = $_POST['radiusunits'];
$dynamicRadius = (isset($DYN_CHECKLIST_RADIUS)?$DYN_CHECKLIST_RADIUS:10);
$taxa = $_POST['taxa'];
$tid = $_POST['tid'];
$interface = $_POST['interface'];

Expand All @@ -18,24 +18,24 @@
if(!is_numeric($radius)) $radius = 0;
if($radiusUnits != 'mi') $radiusUnits == 'km';
if(!is_numeric($dynamicRadius)) $dynamicRadius = 10;
$taxa = filter_var($taxa,FILTER_SANITIZE_STRING);
if(!is_numeric($tid)) $tid = 0;

$dynClManager = new DynamicChecklistManager();

if(is_numeric($radius)){
$dynClid = $dynClManager->createChecklist($lat, $lng, $radius, $radiusUnits, $tid);
}
else{
$dynClid = $dynClManager->createDynamicChecklist($lat, $lng, $dynamicRadius, $tid);
}
if($taxa && !$tid) $tid = $dynClManager->getTid($taxa);
$dynClid = 0;
if($radius) $dynClid = $dynClManager->createChecklist($lat, $lng, $radius, $radiusUnits, $tid);
else $dynClid = $dynClManager->createDynamicChecklist($lat, $lng, $dynamicRadius, $tid);

if($interface == "key"){
header("Location: ".$CLIENT_ROOT."/ident/key.php?dynclid=".$dynClid."&taxon=All Species");
}
else{
header("Location: ".$CLIENT_ROOT."/checklists/checklist.php?dynclid=".$dynClid);
if($dynClid){
if($interface == "key"){
header("Location: ".$CLIENT_ROOT."/ident/key.php?dynclid=".$dynClid."&taxon=All Species");
}
else{
header("Location: ".$CLIENT_ROOT."/checklists/checklist.php?dynclid=".$dynClid);
}
}
ob_flush();
flush();
else echo 'ERROR generating checklist';
$dynClManager->removeOldChecklists();
?>
60 changes: 34 additions & 26 deletions classes/DynamicChecklistManager.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<?php
include_once($SERVER_ROOT.'/config/dbconnection.php');
include_once($SERVER_ROOT.'/classes/Manager.php');

class DynamicChecklistManager {

private $conn;
class DynamicChecklistManager extends Manager {

public function __construct(){
$this->conn = MySQLiConnectionFactory::getCon("write");
parent::__construct(null,'write');
}

public function __destruct(){
if(!($this->conn === null)) $this->conn->close();
parent::__destruct();
}

public function createChecklist($lat, $lng, $radius, $radiusUnits, $tidFilter){
global $SYMB_UID;
//Radius is a set value
//Radius is a set value
if($radiusUnits == "mi") $radius = round($radius*1.6);
$dynPk = 0;
//Create checklist
$sql = 'INSERT INTO fmdynamicchecklists(name,details,expiration,uid) '.
'VALUES ("'.round($lat,5).' '.round($lng,5).' within '.round($radius,1).' km","'.$lat.' '.$lng.' within '.$radius.' km","'.
date('Y-m-d',mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))).'",'.($SYMB_UID?$SYMB_UID:'NULL').')';
//echo $sql;
date('Y-m-d',mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))).'",'.($GLOBALS['SYMB_UID']?$GLOBALS['SYMB_UID']:'NULL').')';
if($this->conn->query($sql)){
$dynPk = $this->conn->insert_id;
//Add species to checklist
Expand All @@ -36,35 +33,32 @@ public function createChecklist($lat, $lng, $radius, $radiusUnits, $tidFilter){
//$sql = 'SELECT count(o.tid) AS speccnt FROM omoccurgeoindex o '.
// 'WHERE (o.DecimalLatitude BETWEEN lat1 AND lat2) AND (o.DecimalLongitude BETWEEN lng1 AND lng2)';
//$this->conn->query($sql);

$sql = 'INSERT INTO fmdyncltaxalink (dynclid, tid) '.
'SELECT DISTINCT '.$dynPk.' AS dynpk, IF(t.rankid=220,t.tid,ts2.parenttid) as tid '.
'FROM omoccurgeoindex o INNER JOIN taxstatus ts ON o.tid = ts.tid '.
'INNER JOIN taxstatus ts2 ON ts.tidaccepted = ts2.tid '.
'INNER JOIN taxa t ON ts2.tid = t.tid ';
if($tidFilter){
$sql .= 'INNER JOIN taxaenumtree e ON ts2.tid = e.tid ';
$sql .= 'INNER JOIN taxaenumtree e ON ts2.tid = e.tid ';
}
$sql .= 'WHERE (t.rankid IN(220,230,240,260)) AND (ts.taxauthid = 1) AND (ts2.taxauthid = 1) '.
'AND (o.DecimalLatitude BETWEEN '.$lat1.' AND '.$lat2.') AND (o.DecimalLongitude BETWEEN '.$lng1.' AND '.$lng2.') ';
if($tidFilter){
$sql .= 'and e.parentTid = '.$tidFilter;
}
//echo $sql; exit;
$this->conn->query($sql);
}

return $dynPk;
}

public function createDynamicChecklist($lat, $lng, $radiusUnit, $tidFilter){
global $SYMB_UID;
$dynPK = 0;

$specCnt = 0;
$radius;
$latRadius; $lngRadius;
$lat1; $lat2; $lng1; $lng2;
$radius = 10;
$lat1 = 0; $lat2 = 0; $lng1 = 0; $lng2 = 0;
$loopCnt = 1;
while($specCnt < 2500 && $loopCnt < 10){
$radius = $radiusUnit*$loopCnt;
Expand All @@ -74,7 +68,7 @@ public function createDynamicChecklist($lat, $lng, $radiusUnit, $tidFilter){
$lat2 = $lat + $latRadius;
$lng1 = $lng - $lngRadius;
$lng2 = $lng + $lngRadius;

$sql1 = 'SELECT count(tid) AS speccnt '.
'FROM omoccurgeoindex '.
'WHERE (DecimalLatitude BETWEEN '.$lat1.' AND '.$lat2.') AND (DecimalLongitude BETWEEN '.$lng1.' AND '.$lng2.')';
Expand All @@ -85,12 +79,11 @@ public function createDynamicChecklist($lat, $lng, $radiusUnit, $tidFilter){
$rs1->free();
$loopCnt++;
}

$radius = $radius*1.60934;
$sql2 = 'INSERT INTO fmdynamicchecklists(name,details,expiration,uid) '.
'VALUES ("'.round($lat,5).' '.round($lng,5).' within '.round($radius,1).' km","'.$lat.' '.$lng.' within '.$radius.' km","'.
date('Y-m-d',mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))).'",'.($SYMB_UID?$SYMB_UID:'NULL').')';
//echo $sql;
date('Y-m-d',mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))).'",'.($GLOBALS['SYMB_UID']?$GLOBALS['SYMB_UID']:'NULL').')';
if($this->conn->query($sql2)){
$dynPK = $this->conn->insert_id;
$sql3 = 'INSERT INTO fmdyncltaxalink (dynclid, tid) '.
Expand All @@ -99,21 +92,36 @@ public function createDynamicChecklist($lat, $lng, $radiusUnit, $tidFilter){
'INNER JOIN taxstatus ts2 ON ts.tidaccepted = ts2.tid '.
'INNER JOIN taxa t ON ts2.tid = t.tid ';
if($tidFilter){
$sql3 .= 'INNER JOIN taxaenumtree e ON ts2.tid = e.tid ';
$sql3 .= 'INNER JOIN taxaenumtree e ON ts2.tid = e.tid ';
}
$sql3 .= 'WHERE (t.rankid >= 220) AND (ts.taxauthid = 1) AND (ts2.taxauthid = 1) '.
'AND (o.DecimalLatitude BETWEEN '.$lat1.' AND '.$lat2.') AND (o.DecimalLongitude BETWEEN '.$lng1.' AND '.$lng2.')';
if($tidFilter){
$sql3 .= 'and e.parentTid = '.$tidFilter;
}
//echo $sql3; exit;
if(!$this->conn->query($sql3)){

$this->errorMessage = 'ERROR adding taxa to checklist: '.$this->conn->error;
echo $this->errorMessage;
}
}
else {
$this->errorMessage = 'ERROR building checklist: '.$this->conn->connect_error;
echo $this->errorMessage;
}
return $dynPK;
}


public function getTid($sciname){
$tid = 0;
$sql = 'SELECT tid FROM taxa WHERE sciname = "'.$this->cleanInStr($sciname).'"';
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$tid = $r->tid;
}
$rs->free();
return $tid;
}

public function removeOldChecklists(){
//Remove any old checklists
$sql1 = 'DELETE dcl.* '.
Expand All @@ -122,6 +130,6 @@ public function removeOldChecklists(){
$this->conn->query($sql1);
$sql2 = 'DELETE FROM fmdynamicchecklists WHERE expiration < NOW()';
$this->conn->query($sql2);
}
}
}
?>
9 changes: 6 additions & 3 deletions classes/ExsiccatiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $c
header ('Content-Type: text/csv');
header ('Content-Disposition: attachment; filename="'.$fileName.'"');
$sqlInsert = '';
$sqlWhere = '';
$fieldArr = array('titleID'=>'et.ometid', 'exsiccatiTitle'=>'et.title', 'abbreviation'=>'et.abbreviation', 'editors'=>'et.editor', 'range'=>'et.exsrange',
'startDate'=>'et.startdate', 'endDate'=>'et.enddate', 'source'=>'et.source', 'sourceIdentifier'=>'et.sourceIdentifier', 'titleNotes'=>'et.notes AS titleNotes');
if(!$titleOnly){
Expand All @@ -222,7 +223,7 @@ public function exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $c
if($collId || $specimenOnly){
$sqlInsert .= 'INNER JOIN omexsiccatiocclink ol ON en.omenid = ol.omenid INNER JOIN omoccurrences o ON ol.occid = o.occid ';
if($imagesOnly) $sqlInsert .= 'INNER JOIN images i ON o.occid = i.occid ';
if($collId) $sqlInsert .= 'WHERE o.collid = '.$collId.' ';
if($collId) $sqlWhere .= 'AND o.collid = '.$collId.' ';
$fieldArr['occid'] = 'o.occid';
$fieldArr['catalogNumber'] = 'o.catalognumber';
$fieldArr['otherCatalogNumbers'] = 'o.othercatalognumbers';
Expand All @@ -239,9 +240,11 @@ public function exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $c
}
}
if($searchTerm){
$sqlInsert .= ($sqlInsert?'AND ':'WHERE ').'et.title LIKE "%'.$searchTerm.'%" OR et.abbreviation LIKE "%'.$searchTerm.'%" OR et.editor LIKE "%'.$searchTerm.'%" ';
$sqlWhere .= 'AND (et.title LIKE "%'.$searchTerm.'%" OR et.abbreviation LIKE "%'.$searchTerm.'%" OR et.editor LIKE "%'.$searchTerm.'%") ';
}
$sql = 'SELECT '.implode(',',$fieldArr).' FROM omexsiccatititles et '.$sqlInsert.'ORDER BY et.title';
$sql = 'SELECT '.implode(',',$fieldArr).' FROM omexsiccatititles et '.$sqlInsert;
if($sqlWhere) $sql .= 'WHERE '.substr($sqlWhere,3);
$sql .= 'ORDER BY et.title';
if(!$titleOnly) $sql .= ', en.exsnumber+0';
$rs = $this->conn->query($sql);
if($rs->num_rows){
Expand Down
16 changes: 14 additions & 2 deletions config/schema-1.0/dev/db_schema_patch_pending.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ ALTER TABLE `referenceobject`


ALTER TABLE `uploadspectemp`
ADD COLUMN `continent` VARCHAR(45) NULL AFTER `locationID`,
ADD COLUMN `islandGroup` VARCHAR(75) NULL AFTER `waterBody`,
ADD COLUMN `island` VARCHAR(75) NULL AFTER `islandGroup`,
ADD COLUMN `countryCode` VARCHAR(5) NULL AFTER `island`,
ADD COLUMN `parentLocationID` VARCHAR(150) NULL AFTER `locationID`,
ADD COLUMN `samplingProtocol` VARCHAR(150) NULL AFTER `parentLocationID`,
ADD COLUMN `georeferencedDate` DATETIME NULL AFTER `georeferencedBy`,
ADD COLUMN `paleoJSON` TEXT NULL AFTER `exsiccatiNotes`;

ALTER TABLE `uploadspectemp`
Expand Down Expand Up @@ -449,9 +456,14 @@ CREATE TABLE `omoccurloanuser` (
CONSTRAINT `FK_occurloan_modifiedByUid` FOREIGN KEY (`modifiedByUid`) REFERENCES `users` (`uid`) ON DELETE SET NULL ON UPDATE CASCADE);


ALTER TABLE `omoccurrences`
ALTER TABLE `omoccurrences`
CHANGE COLUMN `eventID` `eventID` VARCHAR(150) NULL DEFAULT NULL,
CHANGE COLUMN `locationID` `locationID` VARCHAR(150) NULL DEFAULT NULL,
CHANGE COLUMN `labelProject` `labelProject` varchar(250) DEFAULT NULL,
CHANGE COLUMN `georeferenceRemarks` `georeferenceRemarks` VARCHAR(500) NULL DEFAULT NULL,
ADD COLUMN `georeferencedDate` DATETIME NULL AFTER `georeferencedBy`,
ADD COLUMN `parentLocationID` VARCHAR(150) NULL AFTER `locationID`,
ADD COLUMN `samplingProtocol` VARCHAR(150) NULL AFTER `parentLocationID`,
DROP INDEX `idx_occrecordedby`;

ALTER TABLE `omoccurrences`
Expand All @@ -478,7 +490,7 @@ ALTER TABLE `omoccurrences`
ADD UNIQUE INDEX `Index_gui` (`occurrenceID` ASC);

ALTER TABLE `omoccurrences`
ADD INDEX `Index_latlng` (`decimalLatitude` ASC, `decimalLongitude` ASC);
ADD INDEX `Index_latlng` (`decimalLatitude` ASC, `decimalLongitude` ASC);

DELETE FROM omoccurrencesfulltext
WHERE locality IS NULL AND recordedby IS NULL;
Expand Down

0 comments on commit e555f42

Please sign in to comment.