Skip to content

Commit

Permalink
Merge pull request #26 from BioKIC/master
Browse files Browse the repository at this point in the history
Merge BioKIC/Symbiota hot-fixes
  • Loading branch information
egbot committed May 17, 2023
2 parents 22e87ae + 516b7b1 commit 3f26ca6
Show file tree
Hide file tree
Showing 22 changed files with 371 additions and 792 deletions.
11 changes: 3 additions & 8 deletions checklists/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$clArray = $clManager->getClMetaData();
$activateKey = $KEY_MOD_IS_ACTIVE;
$showDetails = 0;
if($clid && $clArray['defaultSettings']){
if(isset($clArray['defaultSettings'])){
$defaultArr = json_decode($clArray['defaultSettings'], true);
$showDetails = $defaultArr['ddetails'];
if(!$defaultOverride){
Expand Down Expand Up @@ -156,7 +156,7 @@ function changeImageSource(elem){
<!-- This is inner text! -->
<div id='innertext'>
<?php
if($clid || $dynClid){
if(($clid || $dynClid) && $clArray){
if($clid && $isEditor){
?>
<div class="printoff" style="float:right;width:auto;">
Expand Down Expand Up @@ -548,12 +548,7 @@ function changeImageSource(elem){
</div>
<div style="margin:3px;">
<?php
echo '<b>';
echo $LANG['TOTAL_TAXA'];
echo '<span class="printoff"> (<a href="https://symbiota.org/symbiota-species-checklist-data-fields/" target="_blank" >';
echo '<span style="font-style:italic;color:green" title="'.(isset($LANG['DETAILS_EXPLANATION'])?$LANG['DETAILS_EXPLANATION']:'').'" >'.(isset($LANG['DETAILS'])?$LANG['DETAILS']:'details').'</span>';
echo '</a>)</span>';
echo '</b>: ';
echo '<b>' . $LANG['TOTAL_TAXA'] . '</b>: ';
echo $clManager->getTaxaCount();
?>
</div>
Expand Down
7 changes: 4 additions & 3 deletions checklists/checklistadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
}
}
elseif($action == 'deleteChecklist'){
$status = $clManager->deleteChecklist($_POST['delclid']);
if($status === true) header('Location: ../index.php');
echo $statusStr = $clManager->getErrorMessage();
if($clManager->deleteChecklist($_POST['delclid'])){
header('Location: ../index.php');
}
else $statusStr = 'ERROR deleting checklist: '.$clManager->getErrorMessage();
}
elseif($action == 'addEditor'){
$statusStr = $clManager->addEditor($_POST['editoruid']);
Expand Down
2 changes: 1 addition & 1 deletion classes/ChecklistAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getMetaData($pid = null){
$inventoryManager = new ImInventories();
$inventoryManager->setClid($this->clid);
$retArr = $inventoryManager->getChecklistMetadata($pid);
$this->clName = $retArr['name'];
if($retArr) $this->clName = $retArr['name'];
}
return $retArr;
}
Expand Down
5 changes: 1 addition & 4 deletions classes/GamesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public function getFlashcardImages(){
}
if($this->taxonFilter) $sql .= 'AND (ts.Family = "'.$this->taxonFilter.'" OR t.sciname Like "'.$this->taxonFilter.'%") ';
$sql .= 'ORDER BY RAND() LIMIT 1000 ';
//echo 'sql: '.$sql; exit;
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_object()){
$retArr[$r->tidaccepted]['tid'] = $r->tid;
Expand Down Expand Up @@ -393,9 +392,7 @@ public function setDynClid($id){
}

public function setTaxonFilter($tValue){
if(preg_match('/^[\D\s]+$/',$tValue)){
$this->taxonFilter = $tValue;
}
$this->taxonFilter = $tValue;
}

public function setShowCommon($sc){
Expand Down
85 changes: 53 additions & 32 deletions classes/ImInventories.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,27 @@ public function getChecklistMetadata($pid){
$retArr['datelastmodified'] = $row->datelastmodified;
}
$result->free();
if($retArr['type'] == 'excludespp'){
$sql = 'SELECT clid FROM fmchklstchildren WHERE clidchild = '.$this->clid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retArr['excludeparent'] = $r->clid;
}
$rs->free();
}
if($pid && is_numeric($pid)){
$sql = 'SELECT clNameOverride, mapChecklist, sortSequence, notes FROM fmchklstprojlink WHERE clid = '.$this->clid.' AND pid = '.$pid;
$rs = $this->conn->query($sql);
if($rs){
if($r = $rs->fetch_object()){
$retArr['clNameOverride'] = $this->cleanOutStr($r->clNameOverride);
$retArr['mapchecklist'] = $r->mapChecklist;
$retArr['sortsequence'] = $r->sortSequence;
if($retArr){
if($retArr['type'] == 'excludespp'){
$sql = 'SELECT clid FROM fmchklstchildren WHERE clidchild = '.$this->clid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retArr['excludeparent'] = $r->clid;
}
$rs->free();
}
if($pid && is_numeric($pid)){
$sql = 'SELECT clNameOverride, mapChecklist, sortSequence, notes FROM fmchklstprojlink WHERE clid = '.$this->clid.' AND pid = '.$pid;
$rs = $this->conn->query($sql);
if($rs){
if($r = $rs->fetch_object()){
$retArr['clNameOverride'] = $this->cleanOutStr($r->clNameOverride);
$retArr['mapchecklist'] = $r->mapChecklist;
$retArr['sortsequence'] = $r->sortSequence;
}
$rs->free();
}
}
}
}
return $retArr;
Expand Down Expand Up @@ -91,7 +93,7 @@ public function insertChecklist($fieldArr){
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('sssssssdddsssisi', $clName, $authors, $type, $locality, $publication, $abstract, $notes, $latCentroid, $longCentroid, $pointRadiusMeters, $access, $defaultSettings, $dynamicSql, $uid, $footprintWkt, $sortSequence);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if($stmt->affected_rows && !$stmt->error){
$clid = $stmt->insert_id;
}
else $this->errorMessage = 'ERROR inserting fmchecklists record (2): '.$stmt->error;
Expand Down Expand Up @@ -132,7 +134,7 @@ public function updateChecklist($inputArr){
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param($typeStr, ...$paramArr);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if(!$stmt->error){
$status = true;
}
else $this->errorMessage = 'ERROR updating fmchecklists record (2): '.$stmt->error;
Expand Down Expand Up @@ -168,23 +170,26 @@ public function updateChecklist($inputArr){
}

public function deleteChecklist(){
$status = true;
$status = false;
$roleArr = $this->getManagers('ClAdmin', 'fmchecklists', $this->clid);
unset($roleArr[$GLOBALS['SYMB_UID']]);
if(!$roleArr){
$sql = 'DELETE FROM fmchecklists WHERE (clid = '.$this->clid.')';
if($this->conn->query($sql)){
//Delete userpermissions reference once patch is submitted
$this->deleteUserRole('ClAdmin', $this->clid, $GLOBALS['SYMB_UID']);
}
else{
$this->errorMessage = 'ERROR attempting to delete checklist: '.$this->conn->error;
$status = false;
$this->deleteChecklistTaxaLinks();
$sql = 'DELETE FROM fmchecklists WHERE clid = ?';
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('i', $this->clid);
$stmt->execute();
if($stmt->affected_rows && !$stmt->error){
$status = true;
//Delete userpermissions reference once patch is submitted
$this->deleteUserRole('ClAdmin', $this->clid, $GLOBALS['SYMB_UID']);
}
else $this->errorMessage = $stmt->error;
$stmt->close();
}
}
else{
$this->errorMessage = 'Checklist cannot be deleted until all editors are removed. Remove editors and then try again.';
$status = false;
}
return $status;
}
Expand All @@ -205,14 +210,30 @@ public function getChecklistArr($pid = 0){
return $retArr;
}

//Checklist taxa linkages
private function deleteChecklistTaxaLinks(){
$status = false;
if($this->clid){
$sql = 'DELETE FROM fmchklsttaxalink WHERE clid = ?';
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('i', $this->clid);
$stmt->execute();
if($stmt->error) $this->errorMessage = $stmt->error;
else $status = true;
$stmt->close();
}
}
return $status;
}

//Child-Parent checklist functions
public function insertChildChecklist($clidChild, $modifiedUid){
$status = false;
$sql = 'INSERT INTO fmchklstchildren(clid, clidchild, modifiedUid) VALUES(?,?,?) ';
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('iii', $this->clid, $clidChild, $modifiedUid);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if($stmt->affected_rows && !$stmt->error){
$status = true;
}
else $this->errorMessage = 'ERROR inserting child checklist record (2): '.$stmt->error;
Expand Down Expand Up @@ -278,7 +299,7 @@ public function insertProject($inputArr){
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('ssssi', $projName, $managers, $fullDescription, $notes, $isPublic);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if($stmt->affected_rows && !$stmt->error){
$newPid = $stmt->insert_id;
$this->pid = $newPid;
}
Expand All @@ -302,7 +323,7 @@ public function updateProject($inputArr){
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('ssssii', $projName, $managers, $fullDescription, $notes, $isPublic, $this->pid);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if(!$stmt->error){
$status = true;
}
else $this->errorMessage = 'ERROR updating fmprojects record (2): '.$stmt->error;
Expand Down Expand Up @@ -384,7 +405,7 @@ public function insertUserRole($uid, $role, $tableName, $tablePK, $uidAssignedBy
if($stmt = $this->conn->prepare($sql)){
$stmt->bind_param('isssi', $uid, $role, $tableName, $tablePK, $uidAssignedBy);
if($stmt->execute()){
if($stmt->affected_rows || !$stmt->error){
if($stmt->affected_rows && !$stmt->error){
$status = true;
}
else $this->errorMessage = 'ERROR inserting user role record (2): '.$stmt->error;
Expand Down
18 changes: 9 additions & 9 deletions classes/OccurrenceEditorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public function setQueryVariables($overrideQry = false){
if(array_key_exists('q_ocrfrag',$_REQUEST) && $_REQUEST['q_ocrfrag']) $this->qryArr['ocr'] = trim($_REQUEST['q_ocrfrag']);
if(array_key_exists('q_imgonly',$_REQUEST) && $_REQUEST['q_imgonly']) $this->qryArr['io'] = 1;
if(array_key_exists('q_withoutimg',$_REQUEST) && $_REQUEST['q_withoutimg']) $this->qryArr['woi'] = 1;
for($x=1;$x<9;$x++){
for($x=1; $x<9; $x++){
if(array_key_exists('q_customandor'.$x,$_REQUEST) && $_REQUEST['q_customandor'.$x]) $this->qryArr['cao'.$x] = $_REQUEST['q_customandor'.$x];
if(array_key_exists('q_customopenparen'.$x,$_REQUEST) && $_REQUEST['q_customopenparen'.$x]) $this->qryArr['cop'.$x] = $_REQUEST['q_customopenparen'.$x];
if(array_key_exists('q_customfield'.$x,$_REQUEST) && $_REQUEST['q_customfield'.$x]) $this->qryArr['cf'.$x] = $_REQUEST['q_customfield'.$x];
if(array_key_exists('q_customtype'.$x,$_REQUEST) && $_REQUEST['q_customtype'.$x]) $this->qryArr['ct'.$x] = $_REQUEST['q_customtype'.$x];
if(array_key_exists('q_customvalue'.$x,$_REQUEST) && $_REQUEST['q_customvalue'.$x]) $this->qryArr['cv'.$x] = trim($_REQUEST['q_customvalue'.$x]);
if(array_key_exists('q_customvalue'.$x,$_REQUEST)) $this->qryArr['cv'.$x] = trim($_REQUEST['q_customvalue'.$x]);
if(array_key_exists('q_customcloseparen'.$x,$_REQUEST) && $_REQUEST['q_customcloseparen'.$x]) $this->qryArr['ccp'.$x] = $_REQUEST['q_customcloseparen'.$x];
}
if(array_key_exists('orderby',$_REQUEST)) $this->qryArr['orderby'] = trim($_REQUEST['orderby']);
Expand Down Expand Up @@ -474,7 +474,7 @@ private function setSqlWhere(){
}
//Custom search fields
$customWhere = '';
for($x=1;$x<9;$x++){
for($x=1; $x<9; $x++){
$cao = (array_key_exists('cao'.$x,$this->qryArr)?$this->cleanInStr($this->qryArr['cao'.$x]):'');
$cop = (array_key_exists('cop'.$x,$this->qryArr)?$this->cleanInStr($this->qryArr['cop'.$x]):'');
$customField = (array_key_exists('cf'.$x,$this->qryArr)?$this->cleanInStr($this->qryArr['cf'.$x]):'');
Expand All @@ -496,14 +496,14 @@ private function setSqlWhere(){
}
if($customField == 'o.otherCatalogNumbers'){
$customWhere .= $cao.' ('.substr($this->setCustomSqlFragment($customField, $customTerm, $customValue, $cao, $cop, $ccp),3).' ';
if($customTerm != 'NOT EQUALS' && $customTerm != 'NOT LIKE'){
if($customTerm != 'NOT_EQUALS' && $customTerm != 'NOT_LIKE'){
$caoOverride = 'OR';
if($customTerm == 'NULL') $caoOverride = 'AND';
$customWhere .= $this->setCustomSqlFragment('id.identifierValue', $customTerm, $customValue, $caoOverride, $cop, $ccp);
}
else{
$customWhere .= 'AND o.occid NOT IN(SELECT occid FROM omoccuridentifiers WHERE identifierValue ';
if($customTerm == 'NOT LIKE') $customWhere .= 'NOT LIKE';
if($customTerm == 'NOT_LIKE') $customWhere .= 'NOT_LIKE';
else $customWhere .= '!=';
$customWhere .= ' "'.$this->cleanInStr($customValue).'")';
}
Expand Down Expand Up @@ -536,22 +536,22 @@ private function setCustomSqlFragment($customField, $customTerm, $customValue, $
elseif($customTerm == 'NOTNULL'){
$sqlFrag .= $cao.($cop?' '.$cop:'').' ('.$customField.' IS NOT NULL) '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'NOT EQUALS' && $customValue){
elseif($customTerm == 'NOT_EQUALS'){
if(!is_numeric($customValue)) $customValue = '"'.$customValue.'"';
$sqlFrag .= $cao.($cop?' '.$cop:'').' (('.$customField.' != '.$customValue.') OR ('.$customField.' IS NULL)) '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'GREATER' && $customValue){
elseif($customTerm == 'GREATER'){
if(!is_numeric($customValue)) $customValue = '"'.$customValue.'"';
$sqlFrag .= $cao.($cop?' '.$cop:'').' ('.$customField.' > '.$customValue.') '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'LESS' && $customValue){
elseif($customTerm == 'LESS'){
if(!is_numeric($customValue)) $customValue = '"'.$customValue.'"';
$sqlFrag .= $cao.($cop?' '.$cop:'').' ('.$customField.' < '.$customValue.') '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'LIKE' && $customValue){
$sqlFrag .= $cao.($cop?' '.$cop:'').' ('.$customField.' LIKE "%'.trim($customValue,'%').'%") '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'NOT LIKE' && $customValue){
elseif($customTerm == 'NOT_LIKE' && $customValue){
$sqlFrag .= $cao.($cop?' '.$cop:'').' (('.$customField.' NOT LIKE "%'.trim($customValue,'%').'%") OR ('.$customField.' IS NULL)) '.($ccp?$ccp.' ':'');
}
elseif($customTerm == 'STARTS' && $customValue){
Expand Down
Loading

0 comments on commit 3f26ca6

Please sign in to comment.