Skip to content

Commit

Permalink
Merge pull request #16 from bryo-lichen/master
Browse files Browse the repository at this point in the history
Exsiccati Dev
  • Loading branch information
egbot authored Feb 9, 2021
2 parents 82736c6 + 3d77435 commit 4c4c557
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
47 changes: 26 additions & 21 deletions classes/ExsiccatiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,36 +208,41 @@ public function getExsOccArr($id, $target = 'omenid'){
return $retArr;
}

public function exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $collId){
$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', 'exsiccatiNumber'=>'en.exsnumber');
public function exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $collId, $titleOnly){
$fileName = 'exsiccatiOutput_'.time().'.csv';
header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header ('Content-Type: text/csv');
header ('Content-Disposition: attachment; filename="'.$fileName.'"');
$sqlInsert = '';
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.' ';
$fieldArr['occid'] = 'o.occid';
$fieldArr['catalogNumber'] = 'o.catalognumber';
$fieldArr['otherCatalogNumbers'] = 'o.othercatalognumbers';
$fieldArr['occurrenceSourceId_dbpk'] = 'o.dbpk';
$fieldArr['collector'] = 'o.recordedby';
$fieldArr['collectorNumber'] = 'o.recordnumber';
$fieldArr['occurrenceNotes'] = 'ol.notes AS occurrenceNotes';
$refUrl = "http://";
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) $refUrl = "https://";
$refUrl .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != 80 && $_SERVER['SERVER_PORT'] != 443) $refUrl .= ':'.$_SERVER["SERVER_PORT"];
$refUrl .= $GLOBALS['CLIENT_ROOT'].'/collections/individual/index.php?occid=';
$fieldArr['referenceUrl'] = 'CONCAT("'.$refUrl.'",o.occid) as referenceUrl';
$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){
$sqlInsert = 'INNER JOIN omexsiccatinumbers en ON et.ometid = en.ometid ';
$fieldArr['exsiccatiNumber'] = 'en.exsnumber';
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.' ';
$fieldArr['occid'] = 'o.occid';
$fieldArr['catalogNumber'] = 'o.catalognumber';
$fieldArr['otherCatalogNumbers'] = 'o.othercatalognumbers';
$fieldArr['occurrenceSourceId_dbpk'] = 'o.dbpk';
$fieldArr['collector'] = 'o.recordedby';
$fieldArr['collectorNumber'] = 'o.recordnumber';
$fieldArr['occurrenceNotes'] = 'ol.notes AS occurrenceNotes';
$refUrl = "http://";
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) $refUrl = "https://";
$refUrl .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != 80 && $_SERVER['SERVER_PORT'] != 443) $refUrl .= ':'.$_SERVER["SERVER_PORT"];
$refUrl .= $GLOBALS['CLIENT_ROOT'].'/collections/individual/index.php?occid=';
$fieldArr['referenceUrl'] = 'CONCAT("'.$refUrl.'",o.occid) as referenceUrl';
}
}
if($searchTerm){
$sqlInsert .= ($sqlInsert?'AND ':'WHERE ').'et.title LIKE "%'.$searchTerm.'%" OR et.abbreviation LIKE "%'.$searchTerm.'%" OR et.editor LIKE "%'.$searchTerm.'%" ';
}
$sql = 'SELECT '.implode(',',$fieldArr).' FROM omexsiccatititles et INNER JOIN omexsiccatinumbers en ON et.ometid = en.ometid '.$sqlInsert.'ORDER BY et.title, en.exsnumber+0';
$sql = 'SELECT '.implode(',',$fieldArr).' FROM omexsiccatititles et '.$sqlInsert.'ORDER BY et.title';
if(!$titleOnly) $sql .= ', en.exsnumber+0';
$rs = $this->conn->query($sql);
if($rs->num_rows){
$out = fopen('php://output', 'w');
Expand Down
11 changes: 7 additions & 4 deletions collections/exsiccati/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@
$statusStr = $exsManager->transferOccurrence($omenId,$_POST['occid'],trim($_POST['targetometid'],'k'),$_POST['targetexsnumber']);
}
}
if($formSubmit == 'dlexsiccati'){
$exsManager->exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $collId);
if($formSubmit == 'dlexs' || $formSubmit == 'dlexs_titleOnly'){
$titleOnly = false;
if($formSubmit == 'dlexs_titleOnly') $titleOnly = true;
$exsManager->exportExsiccatiAsCsv($searchTerm, $specimenOnly, $imagesOnly, $collId, $titleOnly);
exit;
}
?>
Expand Down Expand Up @@ -329,8 +331,9 @@ function buildExsSelect(selectObj){
<input type="radio" name="sortby" value="1" <?php echo ($sortBy == 1?"CHECKED":""); ?> onchange="this.form.submit()">Abbreviation
</div>
<div style="margin-top:5px">
<div style="float:right;" title="Download Exsiccati Records">
<button name="formsubmit" type="submit" value="dlexsiccati"><img src="../../images/dl.png" style="width:15px" /></button>
<div style="float:right;">
<span title="Exsiccati download: titles only"><button name="formsubmit" type="submit" value="dlexs_titleOnly"><img src="../../images/dl.png" style="width:15px" /></button></span>
<span title="Exsiccati download: with numbers and occurrences"><button name="formsubmit" type="submit" value="dlexs"><img src="../../images/dl.png" style="width:15px" /></button></span>
</div>
<div>
<button name="formsubmit" type="submit" value="rebuildList">Rebuild List</button>
Expand Down

0 comments on commit 4c4c557

Please sign in to comment.