Skip to content

Commit

Permalink
Merge pull request egbot#308 from BioKIC/master
Browse files Browse the repository at this point in the history
Merge BioKIC/Symbiota developments
  • Loading branch information
egbot authored Sep 21, 2022
2 parents dba369c + cec2983 commit fff2229
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 250 deletions.
17 changes: 7 additions & 10 deletions checklists/checklistadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@
if(!$clid && isset($_POST['delclid'])) $clid = $_POST['delclid'];
$clManager->setClid($clid);


$statusStr = '';
if($action == 'SubmitAdd'){

//Conform User Checklist permission
if($IS_ADMIN || (array_key_exists('ClAdmin',$USER_RIGHTS) && in_array($clid,$USER_RIGHTS['ClAdmin'])) || array_key_exists('ClCreate',$USER_RIGHTS)){
if($action == 'submitAdd'){
//Conform User Checklist permission
if($IS_ADMIN || (array_key_exists('ClAdmin',$USER_RIGHTS) && in_array($clid,$USER_RIGHTS['ClAdmin'])) || array_key_exists('ClCreate',$USER_RIGHTS)){
$newClid = $clManager->createChecklist($_POST);
header('Location: checklist.php?clid='.$newClid);
}

if($newClid) header('Location: checklist.php?clid='.$newClid);
}
//If we made it here the user does not have any checklist roles. cancel further execution.
$statusStr = 'You do not have permission to create a Checklist.';
$statusStr = 'You do not have permission to create a Checklist. Please contact an administrator.';
}

$isEditor = 0;
if($IS_ADMIN || (array_key_exists('ClAdmin',$USER_RIGHTS) && in_array($clid,$USER_RIGHTS['ClAdmin']))){
$isEditor = 1;

//Submit checklist MetaData edits
if($action == 'SubmitEdit'){
if($action == 'submitEdit'){
$clManager->editMetaData($_POST);
header('Location: checklist.php?clid='.$clid.'&pid='.$pid);
}
Expand Down
10 changes: 2 additions & 8 deletions checklists/checklistadminmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,10 @@ function openMappingPolyAid() {
<div style="clear:both;float:left;margin-top:15px;">
<?php
if($clid){
?>
<input type='submit' name='submit' value='<?php echo (isset($LANG['EDITCHECKLIST'])?$LANG['EDITCHECKLIST']:'Edit Checklist');?>' />
<input type="hidden" name="submitaction" value="SubmitEdit" />
<?php
echo '<button type="submit" name="submitaction" value="submitEdit">'.(isset($LANG['EDITCHECKLIST'])?$LANG['EDITCHECKLIST']:'Edit Checklist').'</button>';
}
else{
?>
<input type='submit' name='submit' value='<?php echo (isset($LANG['ADDCHECKLIST'])?$LANG['ADDCHECKLIST']:'Add Checklist');?>' />
<input type="hidden" name="submitaction" value="SubmitAdd" />
<?php
echo '<button type="submit" name="submitaction" value="submitAdd">'.(isset($LANG['ADDCHECKLIST'])?$LANG['ADDCHECKLIST']:'Add Checklist').'</button>';
}
?>
</div>
Expand Down
167 changes: 76 additions & 91 deletions classes/DwcArchiverCore.php

Large diffs are not rendered by default.

49 changes: 13 additions & 36 deletions classes/DwcArchiverDetermination.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class DwcArchiverDetermination{

public static function getDeterminationArr($schemaType,$extended){
$fieldArr = array();
$fieldArr['coreid'] = 'o.occid';
$termArr['identifiedBy'] = 'http://rs.tdwg.org/dwc/terms/identifiedBy';
$fieldArr['identifiedBy'] = 'd.identifiedBy';
Expand Down Expand Up @@ -65,45 +66,21 @@ private static function trimBySchemaType($detArr,$schemaType,$extended){
return array_diff_key($detArr,array_flip($trimArr));
}

public static function getSqlDeterminations($fieldArr,$conditionSql){
public static function getSql($fieldArr, $tableJoins, $conditionSql){
$sql = '';
if($fieldArr && $conditionSql){
$sqlFrag = '';
foreach($fieldArr as $fieldName => $colName){
if($colName) $sqlFrag .= ', '.$colName;
$sql = 'SELECT ';
$delimiter = '';
foreach($fieldArr as $fieldSql){
if($fieldSql) $sql .= $delimiter.$fieldSql;
$delimiter = ', ';
}
$sql = 'SELECT '.trim($sqlFrag,', ').
' FROM omoccurdeterminations d INNER JOIN omoccurrences o ON d.occid = o.occid '.
'INNER JOIN guidoccurdeterminations g ON d.detid = g.detid '.
'LEFT JOIN taxa t ON d.tidinterpreted = t.tid ';
if(strpos($conditionSql,'ts.taxauthid')){
$sql .= 'LEFT JOIN taxstatus ts ON o.tidinterpreted = ts.tid ';
}
if(stripos($conditionSql,'e.parenttid')){
$sql .= 'LEFT JOIN taxaenumtree e ON o.tidinterpreted = e.tid ';
}
if(strpos($conditionSql,'v.clid')){
//Search criteria came from custom search page
$sql .= 'LEFT JOIN fmvouchers v ON o.occid = v.occid ';
}
if(strpos($conditionSql,'p.point')){
//Search criteria came from map search page
$sql .= 'LEFT JOIN omoccurpoints p ON o.occid = p.occid ';
}
if(strpos($conditionSql,'MATCH(f.recordedby)') || strpos($conditionSql,'MATCH(f.locality)')){
$sql .= 'INNER JOIN omoccurrencesfulltext f ON o.occid = f.occid ';
}
if(stripos($conditionSql,'a.stateid')){
//Search is limited by occurrence attribute
$sql .= 'INNER JOIN tmattributes a ON o.occid = a.occid ';
}
elseif(stripos($conditionSql,'s.traitid')){
//Search is limited by occurrence trait
$sql .= 'INNER JOIN tmattributes a ON o.occid = a.occid '.
'INNER JOIN tmstates s ON a.stateid = s.stateid ';
}
$sql .= $conditionSql.'AND d.appliedstatus = 1 '.
'ORDER BY o.collid';
$sql .= 'FROM omoccurdeterminations d INNER JOIN omoccurrences o ON d.occid = o.occid
INNER JOIN guidoccurdeterminations g ON d.detid = g.detid
LEFT JOIN taxa t ON d.tidinterpreted = t.tid ';
$sql .= $tableJoins;
$sql .= $conditionSql.' AND d.appliedstatus = 1 ';
$sql .= 'ORDER BY o.collid';
//echo '<div>'.$sql.'</div>'; exit;
}
return $sql;
Expand Down
6 changes: 4 additions & 2 deletions classes/DwcArchiverPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public function getDwcaItems($collid = 0){

public function getCollectionList($catID){
$retArr = array();
$serverName = $this->getDomain();
$sql = 'SELECT c.collid, c.collectionname, CONCAT_WS("-",c.institutioncode,c.collectioncode) as instcode, c.guidtarget, c.dwcaurl, c.managementtype, c.dynamicProperties '.
'FROM omcollections c INNER JOIN omcollectionstats s ON c.collid = s.collid '.
'LEFT JOIN omcollcatlink l ON c.collid = l.collid '.
Expand All @@ -255,8 +256,9 @@ public function getCollectionList($catID){
while($r = $rs->fetch_object()){
$retArr[$r->collid]['name'] = $r->collectionname.' ('.$r->instcode.')';
$retArr[$r->collid]['guid'] = $r->guidtarget;
$retArr[$r->collid]['url'] = substr($r->dwcaurl,0,strpos($r->dwcaurl,'/content')).'/collections/datasets/datapublisher.php';
$serverName = $this->getDomain();
$url = $r->dwcaurl;
if($url) $url = substr($url,0,strpos($url,'/content')).'/collections/datasets/datapublisher.php';
$retArr[$r->collid]['url'] = $url;
if(!$r->guidtarget) $retArr[$r->collid]['err'] = 'MISSING_GUID';
elseif($r->dwcaurl && !strpos($serverName, 'localhost') && strpos($r->dwcaurl, str_replace('www.', '', $serverName)) === false) $retArr[$r->collid]['err'] = 'ALREADY_PUB_DOMAIN';
if($r->dynamicProperties && strpos($r->dynamicProperties,'matSample":{"status":1')) $this->materialSampleIsActive = true;
Expand Down
4 changes: 2 additions & 2 deletions classes/ImageShared.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ public static function getImgDim($imgUrl){
$urlPrefix .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != 80 && $_SERVER['SERVER_PORT'] != 443) $urlPrefix .= ':'.$_SERVER["SERVER_PORT"];

if(strpos($imgUrl,$urlPrefix) === 0){
$imgUrl = substr($imgUrl,strlen($urlPrefix));
if(strpos($imgUrl,$urlPrefix.$GLOBALS['IMAGE_ROOT_URL']) === 0){
$imgUrl = substr($imgUrl, strlen($urlPrefix));
}
if(substr($imgUrl,0,1) == '/'){
if($GLOBALS['IMAGE_ROOT_URL'] && strpos($imgUrl,$GLOBALS['IMAGE_ROOT_URL']) === 0){
Expand Down
13 changes: 5 additions & 8 deletions classes/KeyDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,19 @@ public function getTaxaList(){
public function setTaxaListSQL(){
if(!$this->sql){
if($this->clid || $this->dynClid){
$sqlFromBase = 'FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid '.
'INNER JOIN taxa t1 ON t.UnitName1 = t1.UnitName1 AND t.UnitName2 = t1.UnitName2 '.
'INNER JOIN taxstatus ts1 ON ts1.tidaccepted = t1.tid ';
$sqlWhere = 'WHERE (ts.taxauthid = 1) AND (ts1.taxauthid = 1) AND (t.RankId = 220) AND (ts.tid = ts.tidaccepted) ';
$sqlFromBase = 'FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid ';
$sqlWhere = 'WHERE (ts.taxauthid = 1) AND (t.RankId BETWEEN 180 AND 220) AND (ts.tid = ts.tidaccepted) ';
if($this->dynClid){
$sqlFromBase .= 'INNER JOIN fmdyncltaxalink clk ON ts.tid = clk.tid ';
$sqlFromBase .= 'INNER JOIN fmdyncltaxalink clk ON t.tid = clk.tid ';
$sqlWhere .= 'AND (clk.dynclid = '.$this->dynClid.') ';
}
else{
if($this->clType == 'dynamic'){
$sqlFromBase .= 'INNER JOIN omoccurrences o ON ts1.tid = o.TidInterpreted ';
$sqlFromBase .= 'INNER JOIN omoccurrences o ON t.tid = o.TidInterpreted ';
$sqlWhere .= 'AND ('.$this->dynamicSql.') ';
}
else{
$sqlFromBase .= 'INNER JOIN fmchklsttaxalink clk ON ts1.tid = clk.tid ';
$sqlFromBase .= 'INNER JOIN fmchklsttaxalink clk ON t.tid = clk.tid ';
$clidStr = $this->clid;
if($this->childClidArr){
$clidStr .= ','.implode(',',array_keys($this->childClidArr));
Expand Down Expand Up @@ -436,7 +434,6 @@ public function setTaxaListSQL(){
}
}
$this->sql = 'SELECT DISTINCT t.tid, ts.family, t.sciname '.$sqlFromBase.$sqlWhere;
//echo $this->sql;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions classes/OccurrenceDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ public function editDataset($dsid,$name,$notes,$description,$ispublic){
return true;
}

public function createDataset($name,$notes,$description,$ispublic,$uid){
$sql = 'INSERT INTO omoccurdatasets (name,notes,description,ispublic,uid) VALUES("'.$this->cleanInStr($name).'",'.($notes?'"'.$this->cleanInStr($notes).'"':'NULL').','.($description?'"'.$this->cleanInStr($description).'"':'NULL').','.($ispublic?'"'.$this->cleanInStr($ispublic).'"':'"0"').','.$uid.') ';
public function createDataset($name, $notes, $description, $ispublic, $uid){
$sql = 'INSERT INTO omoccurdatasets (name,notes,description,ispublic,uid)
VALUES("'.$this->cleanInStr($name).'",'.($notes?'"'.$this->cleanInStr($notes).'"':'NULL').','.($description?'"'.$this->cleanInStr($description).'"':'NULL').','.($ispublic?'"'.$this->cleanInStr($ispublic).'"':'"0"').','.$uid.') ';
if($this->conn->query($sql)){
$this->datasetId = $this->conn->insert_id;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/OccurrenceEditorDeterminations.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function deleteDetermination($detId){
$occid = 0;

$sql = 'SELECT occid, identifiedBy, dateIdentified, family, sciname, scientificNameAuthorship, tidInterpreted, identificationQualifier, isCurrent, printQueue,
appliedStatus, detType, identificationReferences, identificationRemarks, taxonRemarks, sourceIdentifier, sortSequence
appliedStatus, detType, identificationReferences, identificationRemarks, taxonRemarks, sortSequence
FROM omoccurdeterminations WHERE detid = '.$detId;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_assoc()){
Expand Down
31 changes: 16 additions & 15 deletions classes/OccurrenceEditorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,25 +860,26 @@ public function editOccurrence($postArr, $editorStatus){
$identArr = $this->getIdentifiers($this->occid);
$oldValueArr = array();
//Get current values to be saved within versioning tables
$editFieldArr['occurrence'] = array_intersect($editArr,array_keys($this->fieldArr['occurrence']));
if($editFieldArr['occurrence']){
$sql = 'SELECT o.collid, '.implode(',',$editFieldArr['occurrence']).(in_array('processingstatus',$editFieldArr['occurrence'])?'':',processingstatus').
(in_array('recordenteredby',$editFieldArr['occurrence'])?'':',recordenteredby').' FROM omoccurrences o WHERE o.occid = '.$this->occid;
$editFieldArr = array();
$editFieldArr['omoccurrences'] = array_intersect($editArr,array_keys($this->fieldArr['occurrence']));
if($editFieldArr['omoccurrences']){
$sql = 'SELECT o.collid, '.implode(',',$editFieldArr['omoccurrences']).(in_array('processingstatus',$editFieldArr['omoccurrences'])?'':',processingstatus').
(in_array('recordenteredby',$editFieldArr['omoccurrences'])?'':',recordenteredby').' FROM omoccurrences o WHERE o.occid = '.$this->occid;
$rs = $this->conn->query($sql);
$oldValueArr['occurrence'] = $rs->fetch_assoc();
$rs->free();
}
//Get current paleo values to be saved within versioning tables
$editFieldArr['paleo'] = array_intersect($editArr, $this->fieldArr['paleo']);
if($this->paleoActivated && $editFieldArr['paleo']){
$sql = 'SELECT '.implode(',',$editFieldArr['paleo']).' FROM omoccurpaleo WHERE occid = '.$this->occid;
$editFieldArr['omoccurpaleo'] = array_intersect($editArr, $this->fieldArr['paleo']);
if($this->paleoActivated && $editFieldArr['omoccurpaleo']){
$sql = 'SELECT '.implode(',',$editFieldArr['omoccurpaleo']).' FROM omoccurpaleo WHERE occid = '.$this->occid;
$rs = $this->conn->query($sql);
if($rs->num_rows) $oldValueArr['paleo'] = $rs->fetch_assoc();
$rs->free();
}
//Get current identifiers values to be saved within versioning tables
$editFieldArr['identifier'] = array_intersect($editArr, $this->fieldArr['identifier']);
if($editFieldArr['identifier'] && $identArr){
$editFieldArr['omoccuridentifiers'] = array_intersect($editArr, $this->fieldArr['identifier']);
if($editFieldArr['omoccuridentifiers'] && $identArr){
foreach($identArr[$this->occid] as $idKey => $idArr){
$idStr = '';
if($idArr['name']) $idStr = $idArr['name'].': ';
Expand All @@ -887,8 +888,8 @@ public function editOccurrence($postArr, $editorStatus){
}
}
//Get current exsiccati values to be saved within versioning tables
$editFieldArr['exsiccati'] = array_intersect($editArr, $this->fieldArr['exsiccati']);
if($editFieldArr['exsiccati']){
$editFieldArr['omexsiccatiocclink'] = array_intersect($editArr, $this->fieldArr['exsiccati']);
if($editFieldArr['omexsiccatiocclink']){
$sql = 'SELECT et.ometid, et.title, exsnumber '.
'FROM omexsiccatiocclink el INNER JOIN omexsiccatinumbers en ON el.omenid = en.omenid '.
'INNER JOIN omexsiccatititles et ON en.ometid = et.ometid '.
Expand Down Expand Up @@ -919,20 +920,20 @@ public function editOccurrence($postArr, $editorStatus){
$oldRecordEnteredBy = isset($oldValueArr['occurrence']['recordenteredby'])?$oldValueArr['occurrence']['recordenteredby']:'';
if($oldRecordEnteredBy == 'preprocessed' || (!$oldRecordEnteredBy && ($oldProcessingStatus == 'unprocessed' || $oldProcessingStatus == 'stage 1'))){
$postArr['recordenteredby'] = $GLOBALS['USERNAME'];
$editFieldArr['occurrence'][] = 'recordenteredby';
$editFieldArr['omoccurrences'][] = 'recordenteredby';
}
//Version edits; add edits to omoccuredits
$sqlEditsBase = 'INSERT INTO omoccuredits(occid,reviewstatus,appliedstatus,uid,fieldname,fieldvaluenew,fieldvalueold) '.
'VALUES ('.$this->occid.',1,'.($autoCommit?'1':'0').','.$GLOBALS['SYMB_UID'].',';
foreach($editFieldArr as $tableName => $fieldArr){
if($tableName == 'identifier'){
if($tableName == 'omoccuridentifiers'){
if($fieldArr){
foreach($postArr['idkey'] as $idIndex => $idKey){
$newValue = $postArr['idname'][$idIndex].($postArr['idname'][$idIndex]?': ':'').$postArr['idvalue'][$idIndex];
$oldValue = '';
if(is_numeric($idKey)) $oldValue = $oldValueArr['identifier'][$idKey];
if($oldValue != $newValue){
$sqlEdit = $sqlEditsBase.'"omoccuridentifier","'.$newValue.'","'.$oldValue.'")';
$sqlEdit = $sqlEditsBase.'"omoccuridentifiers","'.$newValue.'","'.$oldValue.'")';
if(!$this->conn->query($sqlEdit)){
$this->errorArr[] = ''.$this->conn->error;
}
Expand All @@ -943,7 +944,7 @@ public function editOccurrence($postArr, $editorStatus){
else{
foreach($fieldArr as $fieldName){
$prefix = $tableName.':';
if($prefix == 'occurrence:') $prefix = '';
if($prefix == 'omoccurrences:') $prefix = '';
if(!array_key_exists($fieldName,$postArr)){
//Field is a checkbox that is unchecked: cultivationstatus, localitysecurity
$postArr[$fieldName] = 0;
Expand Down
14 changes: 3 additions & 11 deletions collections/admin/igsnmapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $CHARSET; ?>">
<title>IGSN GUID Mapper</title>
<?php
$activateJQuery = false;
if(file_exists($SERVER_ROOT.'/includes/head.php')){
include_once($SERVER_ROOT.'/includes/head.php');
}
else{
echo '<link href="'.$CLIENT_ROOT.'/css/jquery-ui.css" type="text/css" rel="stylesheet" />';
echo '<link href="'.$CLIENT_ROOT.'/css/base.css?ver=1" type="text/css" rel="stylesheet" />';
echo '<link href="'.$CLIENT_ROOT.'/css/main.css?ver=1" type="text/css" rel="stylesheet" />';
}
?>
<?php
$activateJQuery = false;
include_once($SERVER_ROOT.'/includes/head.php');
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript">
function validateCredentials(f){
Expand Down
2 changes: 1 addition & 1 deletion collections/datasets/datapublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function checkAllColl(cb) {
if ($errMsg) $inputAttr = 'DISABLED';
elseif ($v['url']) $inputAttr = 'CHECKED';
echo '<input name="coll[]" type="checkbox" value="' . $k . '" ' . $inputAttr . ' />';
echo '<a href="../misc/collprofiles.php?collid=' . $k . '" target="_blank">' . $v['name'] . '</a>';
echo '<a href="../misc/collprofiles.php?collid=' . $k . '" target="_blank">' . $v['name'] . '</a> ';
if ($errMsg) echo '<span style="color:red;margin-left:15px;">' . $errMsg . '</span>';
elseif ($v['url']) echo '<span> - published</span>';
echo '<br/>';
Expand Down
28 changes: 15 additions & 13 deletions collections/datasets/datasetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@
$occid = array_key_exists('occid',$_POST)?$_POST['occid']:0;

//Sanitation
if(!is_numeric($datasetID)) $datasetID = 0;
if(!is_numeric($datasetID) && $datasetID != '--newDataset') $datasetID = 0;

if($action){
$datasetManager = new OccurrenceDataset();
if($datasetID == '--newDataset'){
$name = 'newDataset ('.date('Y-m-d H:i:s').')';
$datasetManager->createDataset($name,'','','',$SYMB_UID);
$datasetID = $datasetManager->getDatasetId();
if($datasetManager->createDataset($name, '', '', '', $SYMB_UID)) $datasetID = $datasetManager->getDatasetId();
else echo $datasetManager->getErrorMessage();
}
$targetLink = 'datasetmanager.php?datasetid='.$datasetID;
if($sourcePage == 'individual') $targetLink = '../individual/index.php?occid='.$occid;
if($action == 'addSelectedToDataset'){
if($occid){
if($datasetManager->addSelectedOccurrences($datasetID, $occid)){
header('Location: '.$targetLink);
if($datasetID){
if($action == 'addSelectedToDataset'){
if($occid){
if($datasetManager->addSelectedOccurrences($datasetID, $occid)){
header('Location: '.$targetLink);
}
else echo $datasetManager->getErrorMessage();
}
else echo $datasetManager->getErrorMessage();
}
}
elseif($action == 'addAllToDataset'){
$occurManager = new OccurrenceManager('write');
if($occurManager->addOccurrencesToDataset($datasetID)) header('Location: '.$targetLink);
else echo $occurManager->getErrorMessage();
elseif($action == 'addAllToDataset'){
$occurManager = new OccurrenceManager('write');
if($occurManager->addOccurrencesToDataset($datasetID)) header('Location: '.$targetLink);
else echo $occurManager->getErrorMessage();
}
}
}
}
Expand Down
Loading

0 comments on commit fff2229

Please sign in to comment.