Skip to content

Commit

Permalink
Merge pull request #29 from BioKIC/master
Browse files Browse the repository at this point in the history
code update
  • Loading branch information
mandrewj authored Jun 16, 2022
2 parents a7af515 + 743f6ea commit 9332ccb
Show file tree
Hide file tree
Showing 41 changed files with 1,392 additions and 950 deletions.
58 changes: 53 additions & 5 deletions admin/portalindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

$portalID = array_key_exists('portalid',$_REQUEST)?$_REQUEST['portalid']:0;
$remoteID = array_key_exists('remoteid',$_REQUEST)?$_REQUEST['remoteid']:0;
$remotePath = array_key_exists('remotePath',$_POST)?$_POST['remotePath']:'';
$formSubmit = array_key_exists('formsubmit',$_POST)?$_POST['formsubmit']:'';

//Sanitation
if(!is_numeric($portalID)) $portalID = 0;
if(!is_numeric($remoteID)) $remoteID = 0;
$remotePath = filter_var($remotePath, FILTER_SANITIZE_URL);

$portalManager = new PortalIndex();

Expand All @@ -29,13 +31,21 @@
<script src="<?php echo $CLIENT_ROOT; ?>/js/jquery.js" type="text/javascript"></script>
<script src="<?php echo $CLIENT_ROOT; ?>/js/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
function validateHandshakeForm(f){
if(f.remotePath.value == ""){
alert("Enter URL to remote portal base index page");
return false;
}
return true;
}
</script>
<style type="text/css">
fieldset{ margin:20px; padding:15px; }
legend{ font-weight: bold; }
label{ }
button{ margin: 20px; }
hr{ margin-top: 15px; margin-bottom: 15px; }
.field-row{ }
</style>
</head>
<body>
Expand All @@ -49,16 +59,53 @@
</div>
<div id="innertext">
<?php
if($isEditor){
if($formSubmit == 'importProfile'){
if($collid = $portalManager->importProfile($portalID, $remoteID)) echo '<div><a href="../collections/misc/collprofiles.php?collid='.$collid.'" target="_blank">New snapshot collection created</a></div>';
else echo '<div>failed to insert new collections: '.$portalManager->getErrorMessage().'</div>';
if(!isset($GLOBALS['ACTIVATE_PORTAL_INDEX'])){
echo 'This feature has not yet been activated within this portal';
}
elseif($isEditor){
if($formSubmit && $formSubmit != 'listCollections'){
echo '<fieldset>';
echo '<legend>Action Panel</legend>';
if($formSubmit == 'importProfile'){
if($collid = $portalManager->importProfile($portalID, $remoteID)) echo '<div><a href="../collections/misc/collprofiles.php?collid='.$collid.'" target="_blank">New snapshot collection created</a></div>';
else echo '<div>failed to insert new collections: '.$portalManager->getErrorMessage().'</div>';
}
elseif($formSubmit == 'initiateHandshake'){
if($resArr = $portalManager->initiateHandshake($remotePath)){
if($resArr['status']) echo '<div>Success - handshake successful: '.$resArr['message'].'</div>';
else echo '<div>ERROR - handshake failed: '.$resArr['message'].'</div>';
//print_r($resArr);
}
else echo '<div>ERROR initiating handshake: '.$portalManager->getErrorMessage().'</div>';
}
echo '</fieldset>';
}
$selfArr = $portalManager->getSelfDetails();
if($formSubmit != 'listCollections'){
?>
<fieldset>
<legend>Current Portal Details</legend>
<div class="field-row"><label>Portal title:</label> <?php echo $selfArr['portalName']; ?></div>
<div class="field-row"><label>Root URL:</label> <?php echo $selfArr['urlRoot']; ?></div>
<div class="field-row"><label>Global Unique Identifier:</label> <?php echo $selfArr['guid']; ?></div>
<div class="field-row"><label>Manager email:</label> <?php echo $selfArr['managerEmail']; ?></div>
<div class="field-row"><label>Software version:</label> <?php echo $selfArr['symbiotaVersion']; ?></div>
<hr />
<div class="handshake-div"><a href="#" onclick="$('.handshake-div').toggle(); return false;">Initiate Handshake with External Portal</a></div>
<div class="handshake-div" style="display:none">
<form action="portalindex.php" method="post" onsubmit="return validateHandshakeForm(this)">
<div class="field-row"><label>Path to Remote Portal:</label> <input name="remotePath" type="text" value="<?php echo $remotePath; ?>" style="width: 500px" /></div>
<div class="field-row"><button name="formsubmit" type="submit" value="initiateHandshake">Initiate Handshake</button></div>
</form>
</div>
</fieldset>
<?php
}
$indexArr = $portalManager->getPortalIndexArr($portalID);
?>
<fieldset>
<legend>Portal Index</legend>
<?php
$indexArr = $portalManager->getPortalIndexArr($portalID);
foreach($indexArr as $portalID => $portalArr){
foreach($portalArr as $fieldName => $fieldValue){
if($fieldValue){
Expand Down Expand Up @@ -160,6 +207,7 @@
}
echo '<hr/>';
}
if(!$indexArr) echo '<div>Portal Index empty. No portals have yet been registered.</div>';
?>
</fieldset>
<?php
Expand Down
19 changes: 13 additions & 6 deletions api/app/Http/Controllers/InstallationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ public function portalHandshake($id, Request $request){
foreach($remoteInstallationArr['results'] as $portal){
if(PortalIndex::where('guid',$portal['guid'])->count()) $currentRegistered++;
elseif($portal['guid'] != $_ENV['PORTAL_GUID']){
//Add remote
PortalIndex::create($portal);
//Touch remote installation but don't wait for a response because propagation across a large network can take awhile
$urlTouch = $portal['urlRoot'].'/api/v2/installation/'.$_ENV['PORTAL_GUID'].'/touch?endpoint='.htmlentities($this->getServerDomain().$_ENV['CLIENT_ROOT']);
$this->getAPIResponce($urlTouch, true);
$newRegistration++;
//If remote exists, add by retriving info directly from source
$remotePing = $portal['urlRoot'].'/api/v2/installation/ping';
if($newRemote = $this->getAPIResponce($remotePing)){
PortalIndex::create($newRemote);
//Touch remote installation but don't wait for a response because propagation across a large network can take awhile
$urlTouch = $portal['urlRoot'].'/api/v2/installation/'.$_ENV['PORTAL_GUID'].'/touch?endpoint='.htmlentities($this->getServerDomain().$_ENV['CLIENT_ROOT']);
$this->getAPIResponce($urlTouch, true);
$newRegistration++;
}
}
}
$responseArr['Current registered remotes obtained from remote library'] = $currentRegistered;
Expand Down Expand Up @@ -306,6 +309,10 @@ public function showOccurrences($id, Request $request){

public function create(Request $request){
/*
$validated = $request->validate([
'portalName' => 'required|max:45',
'urlRoot' => 'required|max:150',
]);
$portalIndex = PortalIndex::create($request->all());
return response()->json($portalIndex, 201);
Expand Down
8 changes: 6 additions & 2 deletions api/vendor/laravel/lumen-framework/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@
require_once($symbBasePath.'/config/dbconnection.php');
foreach(MySQLiConnectionFactory::$SERVERS as $dbArr){
if($dbArr['type'] = 'write'){
$params['connections']['mysql']['host'] = $dbArr['host'];
$params['connections']['mysql']['port'] = $dbArr['port'];
$host = 'localhost';
if(isset($dbArr['host'])) $host = $dbArr['host'];
$params['connections']['mysql']['host'] = $host;
$params['connections']['mysql']['database'] = $dbArr['database'];
$params['connections']['mysql']['username'] = $dbArr['username'];
$params['connections']['mysql']['password'] = $dbArr['password'];
$port = '3306';
if(isset($dbArr['port'])) $port = $dbArr['port'];
$params['connections']['mysql']['port'] = $port;
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions api/vendor/psr/log/src/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface LoggerInterface
*
* @return void
*/
public function emergency(string|\Stringable $message, array $context = []);
public function emergency(string $message, array $context = []);

/**
* Action must be taken immediately.
Expand All @@ -40,7 +40,7 @@ public function emergency(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function alert(string|\Stringable $message, array $context = []);
public function alert(string $message, array $context = []);

/**
* Critical conditions.
Expand All @@ -52,7 +52,7 @@ public function alert(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function critical(string|\Stringable $message, array $context = []);
public function critical(string $message, array $context = []);

/**
* Runtime errors that do not require immediate action but should typically
Expand All @@ -63,7 +63,7 @@ public function critical(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function error(string|\Stringable $message, array $context = []);
public function error(string $message, array $context = []);

/**
* Exceptional occurrences that are not errors.
Expand All @@ -76,7 +76,7 @@ public function error(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function warning(string|\Stringable $message, array $context = []);
public function warning(string $message, array $context = []);

/**
* Normal but significant events.
Expand All @@ -86,7 +86,7 @@ public function warning(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function notice(string|\Stringable $message, array $context = []);
public function notice(string $message, array $context = []);

/**
* Interesting events.
Expand All @@ -98,7 +98,7 @@ public function notice(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function info(string|\Stringable $message, array $context = []);
public function info(string $message, array $context = []);

/**
* Detailed debug information.
Expand All @@ -108,7 +108,7 @@ public function info(string|\Stringable $message, array $context = []);
*
* @return void
*/
public function debug(string|\Stringable $message, array $context = []);
public function debug(string $message, array $context = []);

/**
* Logs with an arbitrary level.
Expand All @@ -121,5 +121,5 @@ public function debug(string|\Stringable $message, array $context = []);
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = []);
public function log($level, string $message, array $context = []);
}
17 changes: 12 additions & 5 deletions checklists/checklistadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
if(!$clid && isset($_POST['delclid'])) $clid = $_POST['delclid'];
$clManager->setClid($clid);


$statusStr = '';
if($action == 'SubmitAdd'){
//Anyone with a login can create a checklist
$newClid = $clManager->createChecklist($_POST);
header('Location: checklist.php?clid='.$newClid);

//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 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 = '';
$isEditor = 0;
if($IS_ADMIN || (array_key_exists('ClAdmin',$USER_RIGHTS) && in_array($clid,$USER_RIGHTS['ClAdmin']))){
$isEditor = 1;
Expand Down Expand Up @@ -58,7 +65,7 @@
}
$clArray = $clManager->getMetaData();
$defaultArr = array();
if($clArray['defaultsettings']){
if(array_key_exists('defaultsettings',$clArray)){
$defaultArr = json_decode($clArray['defaultsettings'], true);
}
?>
Expand Down
3 changes: 3 additions & 0 deletions checklists/clgmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
$pid = $_REQUEST['pid'];
$target = array_key_exists('target',$_REQUEST)?$_REQUEST['target']:'checklists';

//Sanitation
if(!is_numeric($pid)) $pid = 0;

$clManager = new ChecklistManager();
$clManager->setProj($pid);
?>
Expand Down
13 changes: 9 additions & 4 deletions checklists/clsppeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
@include_once($SERVER_ROOT.'/content/lang/checklists/clsppeditor.'.$LANG_TAG.'.php');
header("Content-Type: text/html; charset=".$CHARSET);

$clid = array_key_exists("clid",$_REQUEST)?$_REQUEST["clid"]:"";
$tid = array_key_exists("tid",$_REQUEST)?$_REQUEST["tid"]:"";
$tabIndex = array_key_exists("tabindex",$_POST)?$_POST["tabindex"]:0;
$action = array_key_exists("action",$_POST)?$_POST["action"]:"";
$clid = array_key_exists('clid',$_REQUEST)?$_REQUEST['clid']:0;
$tid = array_key_exists('tid',$_REQUEST)?$_REQUEST['tid']:0;
$tabIndex = array_key_exists('tabindex',$_POST)?$_POST['tabindex']:0;
$action = array_key_exists('action',$_POST)?$_POST['action']:'';

//Sanitation
if(!is_numeric($clid)) $clid = 0;
if(!is_numeric($tid)) $tid = 0;
if(!is_numeric($tabIndex)) $tabIndex = 0;

$isEditor = false;
if($IS_ADMIN || (array_key_exists("ClAdmin",$USER_RIGHTS) && in_array($clid,$USER_RIGHTS["ClAdmin"]))){
Expand Down
58 changes: 31 additions & 27 deletions classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public function getOccurrenceCnt(){
//if($this->schemaType != 'backup') $sql .= ' LIMIT 1000000';
if($sql){
$sql = 'SELECT COUNT(o.occid) as cnt '.$sql;
//echo $sql; exit;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
$retStr = $r->cnt;
Expand Down Expand Up @@ -292,6 +291,7 @@ private function applyConditions(){
$taxaManager = new OccurrenceTaxaManager();
$taxaArr = array();
$taxaArr['taxa'] = implode(';',$condArr['EQUALS']);
if($field == 'family') $taxaArr['taxontype'] = 3;
$taxaManager->setTaxonRequestVariable($taxaArr);
$sqlFrag .= $taxaManager->getTaxonWhereFrag();
}
Expand Down Expand Up @@ -1641,20 +1641,23 @@ private function writeOccurrenceFile(){
if($collidStr) $this->setCollArr(trim($collidStr,','));
}

//$dwcOccurManager->setUpperTaxonomy();
$dwcOccurManager->setTaxonRank();

$materialSampleHandler = null;
if($this->includeMaterialSample){
$collid = key($this->collArr);
if(isset($this->collArr[$collid]['matSample'])){
$this->logOrEcho('Creating material sample extension file ('.date('h:i:s A').')... ');
$materialSampleHandler = new DwcArchiverMaterialSample($this->conn);
$materialSampleHandler->initiateProcess($this->targetPath.$this->ts.'-matSample'.$this->fileExt);
$materialSampleHandler->setSchemaType($this->schemaType);
$this->fieldArrMap['materialSample'] = $materialSampleHandler->getFieldArrTerms();
if($this->schemaType != 'coge'){
//$dwcOccurManager->setUpperTaxonomy();
$dwcOccurManager->setTaxonRank();

if($this->includeMaterialSample){
$collid = key($this->collArr);
if(isset($this->collArr[$collid]['matSample'])){
$this->logOrEcho('Creating material sample extension file ('.date('h:i:s A').')... ');
$materialSampleHandler = new DwcArchiverMaterialSample($this->conn);
$materialSampleHandler->initiateProcess($this->targetPath.$this->ts.'-matSample'.$this->fileExt);
$materialSampleHandler->setSchemaType($this->schemaType);
$this->fieldArrMap['materialSample'] = $materialSampleHandler->getFieldArrTerms();
}
}
}

//echo $sql; exit;
if($rs = $this->dataConn->query($sql,MYSQLI_USE_RESULT)){
$this->setServerDomain();
Expand Down Expand Up @@ -1738,22 +1741,23 @@ private function writeOccurrenceFile(){
elseif($this->schemaType == 'backup') unset($r['collID']);

if($ocnStr = $dwcOccurManager->getAdditionalCatalogNumberStr($r['occid'])) $r['otherCatalogNumbers'] = $ocnStr;
if($exsArr = $dwcOccurManager->getExsiccateArr($r['occid'])){
$exsStr = $exsArr['exsStr'];
if(isset($r['occurrenceRemarks']) && $r['occurrenceRemarks']) $exsStr = $r['occurrenceRemarks'].'; '.$exsStr;
$r['occurrenceRemarks'] = $exsStr;
$dynProp = 'exsiccatae: '.$exsArr['exsJson'];
if(isset($r['dynamicProperties']) && $r['dynamicProperties']) $dynProp = $r['dynamicProperties'].'; '.$dynProp;
$r['dynamicProperties'] = $dynProp;
if($this->schemaType != 'coge'){
if($exsArr = $dwcOccurManager->getExsiccateArr($r['occid'])){
$exsStr = $exsArr['exsStr'];
if(isset($r['occurrenceRemarks']) && $r['occurrenceRemarks']) $exsStr = $r['occurrenceRemarks'].'; '.$exsStr;
$r['occurrenceRemarks'] = $exsStr;
$dynProp = 'exsiccatae: '.$exsArr['exsJson'];
if(isset($r['dynamicProperties']) && $r['dynamicProperties']) $dynProp = $r['dynamicProperties'].'; '.$dynProp;
$r['dynamicProperties'] = $dynProp;
}
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;
}
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);
if($rankStr = $dwcOccurManager->getTaxonRank($r['rankid'])) $r['t_taxonRank'] = $rankStr;
unset($r['rankid']);

$this->encodeArr($r);
$this->addcslashesArr($r);
$this->writeOutRecord($fh,$r);
Expand Down Expand Up @@ -2139,10 +2143,10 @@ public function setServerDomain($domain = ''){
$this->serverDomain = $domain;
}
elseif(!$this->serverDomain){
$this->serverDomain = "http://";
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) $this->serverDomain = "https://";
$this->serverDomain .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != 80 && $_SERVER['SERVER_PORT'] != 443) $this->serverDomain .= ':'.$_SERVER["SERVER_PORT"];
$this->serverDomain = 'http://';
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) $this->serverDomain = 'https://';
$this->serverDomain .= $_SERVER['SERVER_NAME'];
if($_SERVER['SERVER_PORT'] && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) $this->serverDomain .= ':'.$_SERVER['SERVER_PORT'];
}
}

Expand Down
Loading

0 comments on commit 9332ccb

Please sign in to comment.