public function occurrenceAdd($postArr) { $occid = 0; if ($this->collid) { if ($this->isEditor()) { $allowedFields = array('collid' => 'n', 'catalognumber' => 's', 'othercatalognumbers' => 's', 'sciname' => 's', 'tidinterpreted' => 's', 'family' => 's', 'scientificnameauthorship' => 's', 'localitysecurity' => 'n', 'country' => 's', 'stateprovince' => 's', 'county' => 's', 'processingstatus' => 's', 'recordedby' => 's', 'recordnumber' => 's', 'eventdate' => 'd', 'language' => 's'); if (isset($postArr['stateprovince']) && $postArr['stateprovince'] && strlen($postArr['stateprovince']) == 2) { $postArr['stateprovince'] = $this->translateStateAbbreviation($postArr['stateprovince']); } //If country is NULL and state populated, grab country from geo-lookup tables if ((!isset($postArr['country']) || !$postArr['country']) && isset($postArr['stateprovince']) && $postArr['stateprovince']) { $postArr['country'] = $this->getCountry($postArr['stateprovince']); } //Add record $sql1 = ''; $sql2 = ''; foreach ($allowedFields as $f => $dataType) { $sql1 .= ',' . $f; if (array_key_exists($f, $postArr) && ($postArr[$f] || $postArr[$f] === 0)) { $v = $postArr[$f]; if ($dataType == 'n' && is_numeric($v)) { $sql2 .= ',' . $v; } else { $sql2 .= ',"' . $this->cleanInStr($v) . '"'; } } else { $sql2 .= ',NULL'; } } $sql = 'INSERT INTO omoccurrences(' . trim($sql1, ' ,') . ',recordenteredby,dateentered) ' . 'VALUES(' . trim($sql2, ' ,') . ',"' . $GLOBALS['USERNAME'] . '","' . date('Y-m-d H:i:s') . '")'; //echo $sql; if ($this->conn->query($sql)) { $occid = $this->conn->insert_id; //Update collection stats $this->conn->query('UPDATE omcollectionstats SET recordcnt = recordcnt + 1 WHERE collid = ' . $this->collid); //Create and insert Symbiota GUID (UUID) $guid = UuidFactory::getUuidV4(); if (!$this->conn->query('INSERT INTO guidoccurrences(guid,occid) VALUES("' . $guid . '",' . $occid . ')')) { $this->errorStr = '(WARNING: Symbiota GUID mapping failed) '; } } else { $this->errorStr = 'ERROR adding occurrence record: ' . $this->conn->error; } } } return $occid; }
private function writeEmlFile_old() { global $clientRoot, $defaultTitle, $adminEmail; $this->logOrEcho("Creating eml.xml (" . date('h:i:s A') . ")... "); $urlPathPrefix = 'http://' . $_SERVER["SERVER_NAME"] . $clientRoot . (substr($clientRoot, -1) == '/' ? '' : '/'); //Create new DOM document $newDoc = new DOMDocument('1.0', 'UTF-8'); //Add root element $rootElem = $newDoc->createElement('eml:eml'); $rootElem->setAttribute('xmlns:eml', 'eml://ecoinformatics.org/eml-2.1.1'); $rootElem->setAttribute('xmlns:dc', 'http://purl.org/dc/terms/'); $rootElem->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootElem->setAttribute('xsi:schemaLocation', 'eml://ecoinformatics.org/eml-2.1.1 http://rs.gbif.org/schema/eml-gbif-profile/1.0.1/eml.xsd'); $rootElem->setAttribute('packageId', UuidFactory::getUuidV4()); $rootElem->setAttribute('system', 'http://symbiota.org'); $rootElem->setAttribute('scope', 'system'); $rootElem->setAttribute('xml:lang', 'eng'); $newDoc->appendChild($rootElem); $cArr = array(); $datasetElem = $newDoc->createElement('dataset'); $rootElem->appendChild($datasetElem); $datasetElem->appendChild($newDoc->createElement('alternateIdentifier', UuidFactory::getUuidV4())); $titleElem = $newDoc->createElement('title', $this->title); $titleElem->setAttribute('xml:lang', 'eng'); $datasetElem->appendChild($titleElem); $creatorElem = $newDoc->createElement('creator'); $creatorElem->appendChild($newDoc->createElement('organizationName', $defaultTitle)); $creatorElem->appendChild($newDoc->createElement('electronicMailAddress', $adminEmail)); $creatorElem->appendChild($newDoc->createElement('onlineUrl', $urlPathPrefix . 'index.php')); $datasetElem->appendChild($creatorElem); $mdElem = $newDoc->createElement('metadataProvider'); $mdElem->appendChild($newDoc->createElement('organizationName', $defaultTitle)); $mdElem->appendChild($newDoc->createElement('electronicMailAddress', $adminEmail)); $mdElem->appendChild($newDoc->createElement('onlineUrl', $urlPathPrefix . 'index.php')); $datasetElem->appendChild($mdElem); $datasetElem->appendChild($newDoc->createElement('pubDate', date("Y-m-d"))); $datasetElem->appendChild($newDoc->createElement('language', 'eng')); $abstractElem = $newDoc->createElement('abstract'); $abstractElem->appendChild($newDoc->createElement('para', $this->description)); $datasetElem->appendChild($abstractElem); $tempFileName = $this->targetPath . $this->ts . '-eml.xml'; $newDoc->save($tempFileName); $this->zipArchive->addFile($tempFileName); $this->zipArchive->renameName($tempFileName, 'eml.xml'); $this->logOrEcho("Done!! (" . date('h:i:s A') . ")\n"); }
public function getEmlDom($emlArr = null) { if (!$emlArr) { $emlArr = $this->getEmlArr(); } //Create new DOM document $newDoc = new DOMDocument('1.0', $this->charSetOut); //Add root element $rootElem = $newDoc->createElement('eml:eml'); $rootElem->setAttribute('xmlns:eml', 'eml://ecoinformatics.org/eml-2.1.1'); $rootElem->setAttribute('xmlns:dc', 'http://purl.org/dc/terms/'); $rootElem->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootElem->setAttribute('xsi:schemaLocation', 'eml://ecoinformatics.org/eml-2.1.1 http://rs.gbif.org/schema/eml-gbif-profile/1.0.1/eml.xsd'); $rootElem->setAttribute('packageId', UuidFactory::getUuidV4()); $rootElem->setAttribute('system', 'http://symbiota.org'); $rootElem->setAttribute('scope', 'system'); $rootElem->setAttribute('xml:lang', 'eng'); $newDoc->appendChild($rootElem); $cArr = array(); $datasetElem = $newDoc->createElement('dataset'); $rootElem->appendChild($datasetElem); if (array_key_exists('alternateIdentifier', $emlArr)) { foreach ($emlArr['alternateIdentifier'] as $v) { $altIdElem = $newDoc->createElement('alternateIdentifier'); $altIdElem->appendChild($newDoc->createTextNode($v)); $datasetElem->appendChild($altIdElem); } } if (array_key_exists('title', $emlArr)) { $titleElem = $newDoc->createElement('title'); $titleElem->setAttribute('xml:lang', 'eng'); $titleElem->appendChild($newDoc->createTextNode($emlArr['title'])); $datasetElem->appendChild($titleElem); } if (array_key_exists('creator', $emlArr)) { $createArr = $emlArr['creator']; foreach ($createArr as $childArr) { $creatorElem = $newDoc->createElement('creator'); if (isset($childArr['attr'])) { $attrArr = $childArr['attr']; unset($childArr['attr']); foreach ($attrArr as $atKey => $atValue) { $creatorElem->setAttribute($atKey, $atValue); } } foreach ($childArr as $k => $v) { $newChildElem = $newDoc->createElement($k); $newChildElem->appendChild($newDoc->createTextNode($v)); $creatorElem->appendChild($newChildElem); } $datasetElem->appendChild($creatorElem); } } if (array_key_exists('metadataProvider', $emlArr)) { $mdArr = $emlArr['metadataProvider']; foreach ($mdArr as $childArr) { $mdElem = $newDoc->createElement('metadataProvider'); foreach ($childArr as $k => $v) { $newChildElem = $newDoc->createElement($k); $newChildElem->appendChild($newDoc->createTextNode($v)); $mdElem->appendChild($newChildElem); } $datasetElem->appendChild($mdElem); } } if (array_key_exists('pubDate', $emlArr) && $emlArr['pubDate']) { $pubElem = $newDoc->createElement('pubDate'); $pubElem->appendChild($newDoc->createTextNode($emlArr['pubDate'])); $datasetElem->appendChild($pubElem); } $langStr = 'eng'; if (array_key_exists('language', $emlArr) && $emlArr) { $langStr = $emlArr['language']; } $langElem = $newDoc->createElement('language'); $langElem->appendChild($newDoc->createTextNode($langStr)); $datasetElem->appendChild($langElem); if (array_key_exists('description', $emlArr) && $emlArr['description']) { $abstractElem = $newDoc->createElement('abstract'); $paraElem = $newDoc->createElement('para'); $paraElem->appendChild($newDoc->createTextNode($emlArr['description'])); $abstractElem->appendChild($paraElem); $datasetElem->appendChild($abstractElem); } if (array_key_exists('contact', $emlArr)) { $contactArr = $emlArr['contact']; $contactElem = $newDoc->createElement('contact'); $addrArr = array(); if (isset($contactArr['addr'])) { $addrArr = $contactArr['addr']; unset($contactArr['addr']); } foreach ($contactArr as $contactKey => $contactValue) { $conElem = $newDoc->createElement($contactKey); $conElem->appendChild($newDoc->createTextNode($contactValue)); $contactElem->appendChild($conElem); } if (isset($contactArr['addr'])) { $addressElem = $newDoc->createElement('address'); foreach ($addrArr as $aKey => $aVal) { $childAddrElem = $newDoc->createElement($aKey); $childAddrElem->appendChild($newDoc->createTextNode($aVal)); $addressElem->appendChild($childAddrElem); } $contactElem->appendChild($addressElem); } $datasetElem->appendChild($contactElem); } if (array_key_exists('associatedParty', $emlArr)) { $associatedPartyArr = $emlArr['associatedParty']; foreach ($associatedPartyArr as $assocKey => $assocArr) { $assocElem = $newDoc->createElement('associatedParty'); $addrArr = array(); if (isset($assocArr['address'])) { $addrArr = $assocArr['address']; unset($assocArr['address']); } foreach ($assocArr as $aKey => $aArr) { $childAssocElem = $newDoc->createElement($aKey); $childAssocElem->appendChild($newDoc->createTextNode($aArr)); $assocElem->appendChild($childAssocElem); } if ($addrArr) { $addrElem = $newDoc->createElement('address'); foreach ($addrArr as $addrKey => $addrValue) { $childAddrElem = $newDoc->createElement($addrKey); $childAddrElem->appendChild($newDoc->createTextNode($addrValue)); $addrElem->appendChild($childAddrElem); } $assocElem->appendChild($addrElem); } $datasetElem->appendChild($assocElem); } } if (array_key_exists('intellectualRights', $emlArr)) { $rightsElem = $newDoc->createElement('intellectualRights'); $paraElem = $newDoc->createElement('para'); $paraElem->appendChild($newDoc->createTextNode($emlArr['intellectualRights'])); $rightsElem->appendChild($paraElem); $datasetElem->appendChild($rightsElem); } $symbElem = $newDoc->createElement('symbiota'); $dateElem = $newDoc->createElement('dateStamp'); $dateElem->appendChild($newDoc->createTextNode(date("c"))); $symbElem->appendChild($dateElem); //Citation $id = UuidFactory::getUuidV4(); $citeElem = $newDoc->createElement('citation'); $citeElem->appendChild($newDoc->createTextNode($GLOBALS['defaultTitle'] . ' - ' . $id)); $citeElem->setAttribute('identifier', $id); $symbElem->appendChild($citeElem); //Physical $physicalElem = $newDoc->createElement('physical'); $physicalElem->appendChild($newDoc->createElement('characterEncoding', $this->charSetOut)); //format $dfElem = $newDoc->createElement('dataFormat'); $edfElem = $newDoc->createElement('externallyDefinedFormat'); $dfElem->appendChild($edfElem); $edfElem->appendChild($newDoc->createElement('formatName', 'Darwin Core Archive')); $physicalElem->appendChild($dfElem); $symbElem->appendChild($physicalElem); //Collection data if (array_key_exists('collMetadata', $emlArr)) { foreach ($emlArr['collMetadata'] as $k => $collArr) { $collArr = $this->utf8EncodeArr($collArr); $collElem = $newDoc->createElement('collection'); if (isset($collArr['attr']) && $collArr['attr']) { $attrArr = $collArr['attr']; unset($collArr['attr']); foreach ($attrArr as $attrKey => $attrValue) { $collElem->setAttribute($attrKey, $attrValue); } } $abstractStr = ''; if (isset($collArr['abstract']) && $collArr['abstract']) { $abstractStr = $collArr['abstract']; unset($collArr['abstract']); } foreach ($collArr as $collKey => $collValue) { $collElem2 = $newDoc->createElement($collKey); $collElem2->appendChild($newDoc->createTextNode($collValue)); $collElem->appendChild($collElem2); } if ($abstractStr) { $abstractElem = $newDoc->createElement('abstract'); $abstractElem2 = $newDoc->createElement('para'); $abstractElem2->appendChild($newDoc->createTextNode($abstractStr)); $abstractElem->appendChild($abstractElem2); $collElem->appendChild($abstractElem); } $symbElem->appendChild($collElem); } } $metaElem = $newDoc->createElement('metadata'); $metaElem->appendChild($symbElem); $addMetaElem = $newDoc->createElement('additionalMetadata'); $addMetaElem->appendChild($metaElem); $rootElem->appendChild($addMetaElem); return $newDoc; }
public function populateGuids($collId = 0) { set_time_limit(1000); $this->echoStr("Starting batch GUID processing (" . date('Y-m-d h:i:s A') . ")\n"); //Populate Collection GUIDs $this->echoStr("Populating collection GUIDs (all collections by default)"); $sql = 'SELECT collid FROM omcollections WHERE collectionguid IS NULL '; $rs = $this->conn->query($sql); $recCnt = 0; if ($rs->num_rows) { while ($r = $rs->fetch_object()) { $guid = UuidFactory::getUuidV4(); $insSql = 'UPDATE omcollections SET collectionguid = "' . $guid . '" ' . 'WHERE collectionguid IS NULL AND collid = ' . $r->collid; if (!$this->conn->query($insSql)) { $this->echoStr('ERROR: ' . $this->conn->error); } $recCnt++; } $rs->free(); } $this->echoStr("Finished: {$recCnt} collection records processed\n"); //Populate occurrence GUIDs $this->echoStr("Populating occurrence GUIDs\n"); $sql = 'SELECT o.occid ' . 'FROM omoccurrences o LEFT JOIN guidoccurrences g ON o.occid = g.occid ' . 'WHERE g.occid IS NULL '; //$sql = 'SELECT o.occid '. // 'FROM omoccurrences o '. // 'WHERE o.occid NOT IN(SELECT occid FROM guidoccurrences WHERE occid IS NOT NULL) '; if ($collId) { $sql .= 'AND o.collid = ' . $collId; } $rs = $this->conn->query($sql); $recCnt = 0; if ($rs->num_rows) { while ($r = $rs->fetch_object()) { $guid = UuidFactory::getUuidV4(); $insSql = 'INSERT INTO guidoccurrences(guid,occid) ' . 'VALUES("' . $guid . '",' . $r->occid . ')'; if (!$this->conn->query($insSql)) { $this->echoStr('ERROR: occur guids' . $this->conn->error); } $recCnt++; if ($recCnt % 1000 === 0) { $this->echoStr($recCnt . ' records processed'); } } $rs->free(); } $this->echoStr("Finished: {$recCnt} occurrence records processed\n"); //Populate determination GUIDs $this->echoStr("Populating determination GUIDs\n"); $sql = 'SELECT d.detid FROM omoccurdeterminations d LEFT JOIN guidoccurdeterminations g ON d.detid = g.detid '; if ($collId) { $sql .= 'INNER JOIN omoccurrences o ON d.occid = o.occid '; } $sql .= 'WHERE g.detid IS NULL '; if ($collId) { $sql .= 'AND o.collid = ' . $collId; } //$sql = 'SELECT d.detid FROM omoccurdeterminations d '; //if($collId) $sql .= 'INNER JOIN omoccurrences o ON d.occid = o.occid '; //$sql .= 'WHERE d.detid NOT IN(SELECT detid FROM guidoccurdeterminations WHERE detid IS NOT NULL) '; //if($collId) $sql .= 'AND o.collid = '.$collId; $rs = $this->conn->query($sql); $recCnt = 0; if ($rs->num_rows) { while ($r = $rs->fetch_object()) { $guid = UuidFactory::getUuidV4(); $insSql = 'INSERT INTO guidoccurdeterminations(guid,detid) ' . 'VALUES("' . $guid . '",' . $r->detid . ')'; if (!$this->conn->query($insSql)) { $this->echoStr('ERROR: det guids ' . $this->conn->error); } $recCnt++; if ($recCnt % 1000 === 0) { $this->echoStr($recCnt . ' records processed'); } } $rs->free(); } $this->echoStr("Finished: {$recCnt} determination records processed\n"); //Populate image GUIDs $this->echoStr("Populating image GUIDs\n"); $sql = 'SELECT i.imgid FROM images i LEFT JOIN guidimages g ON i.imgid = g.imgid '; if ($collId) { $sql .= 'INNER JOIN omoccurrences o ON i.occid = o.occid '; } $sql .= 'WHERE g.imgid IS NULL '; if ($collId) { $sql .= 'AND o.collid = ' . $collId; } //$sql = 'SELECT i.imgid FROM images i '; //if($collId) $sql .= 'INNER JOIN omoccurrences o ON i.occid = o.occid '; //$sql .= 'WHERE i.imgid NOT IN(SELECT imgid FROM guidimages WHERE imgid IS NOT NULL) '; //if($collId) $sql .= 'AND o.collid = '.$collId; //echo $sql; $rs = $this->conn->query($sql); $recCnt = 0; if ($rs->num_rows) { while ($r = $rs->fetch_object()) { $guid = UuidFactory::getUuidV4(); $insSql = 'INSERT INTO guidimages(guid,imgid) ' . 'VALUES("' . $guid . '",' . $r->imgid . ')'; if (!$this->conn->query($insSql)) { $this->echoStr('ERROR: image guids; ' . $this->conn->error); } $recCnt++; if ($recCnt % 1000 === 0) { $this->echoStr($recCnt . ' records processed'); } } $rs->free(); } $this->echoStr("Finished: {$recCnt} image records processed\n"); $this->echoStr("GUID batch processing complete (" . date('Y-m-d h:i:s A') . ")\n"); }
public function databaseImage($imgWebUrl, $imgTnUrl, $imgLgUrl, $tid) { global $paramsArr; $status = true; if ($imgWebUrl) { $urlBase = $this->getUrlBase(); if (strtolower(substr($imgWebUrl, 0, 7)) != 'http://' && strtolower(substr($imgWebUrl, 0, 8)) != 'https://') { $imgWebUrl = $urlBase . $imgWebUrl; } if ($imgTnUrl && strtolower(substr($imgTnUrl, 0, 7)) != 'http://' && strtolower(substr($imgTnUrl, 0, 8)) != 'https://') { $imgTnUrl = $urlBase . $imgTnUrl; } if ($imgLgUrl && strtolower(substr($imgLgUrl, 0, 7)) != 'http://' && strtolower(substr($imgLgUrl, 0, 8)) != 'https://') { $imgLgUrl = $urlBase . $imgLgUrl; } //If is an occurrence image, get tid from occurrence if (!$tid && $this->occid) { $sql1 = 'SELECT tidinterpreted FROM omoccurrences WHERE tidinterpreted IS NOT NULL AND occid = ' . $this->occid; $rs1 = $this->conn->query($sql1); if ($r1 = $rs1->fetch_object()) { $tid = $r1->tidinterpreted; } $rs1->free(); } //Save currently loaded record $sql = 'INSERT INTO images (tid, url, thumbnailurl, originalurl, photographer, photographeruid, caption, ' . 'owner, sourceurl, copyright, locality, occid, notes, username, sortsequence, sourceIdentifier, ' . ' rights, accessrights) ' . 'VALUES (' . ($tid ? $tid : 'NULL') . ',"' . $imgWebUrl . '",' . ($imgTnUrl ? '"' . $imgTnUrl . '"' : 'NULL') . ',' . ($imgLgUrl ? '"' . $imgLgUrl . '"' : 'NULL') . ',' . ($this->photographer ? '"' . $this->photographer . '"' : 'NULL') . ',' . ($this->photographerUid ? $this->photographerUid : 'NULL') . ',' . ($this->caption ? '"' . $this->caption . '"' : 'NULL') . ',' . ($this->owner ? '"' . $this->owner . '"' : 'NULL') . ',' . ($this->sourceUrl ? '"' . $this->sourceUrl . '"' : 'NULL') . ',' . ($this->copyright ? '"' . $this->copyright . '"' : 'NULL') . ',' . ($this->locality ? '"' . $this->locality . '"' : 'NULL') . ',' . ($this->occid ? $this->occid : 'NULL') . ',' . ($this->notes ? '"' . $this->notes . '"' : 'NULL') . ',"' . $this->cleanInStr($paramsArr['un']) . '",' . ($this->sortSeq ? $this->sortSeq : '50') . ',' . ($this->sourceIdentifier ? '"' . $this->sourceIdentifier . '"' : 'NULL') . ',' . ($this->rights ? '"' . $this->rights . '"' : 'NULL') . ',' . ($this->accessrights ? '"' . $this->accessrights . '"' : 'NULL') . ')'; //echo $sql; exit; if ($this->conn->query($sql)) { //Create and insert Symbiota GUID for image(UUID) $guid = UuidFactory::getUuidV4(); $this->activeImgId = $this->conn->insert_id; if (!$this->conn->query('INSERT INTO guidimages(guid,imgid) VALUES("' . $guid . '",' . $this->activeImgId . ')')) { $this->errArr[] = ' (Warning: Symbiota GUID mapping failed)'; } } else { $this->errArr[] = 'ERROR loading data: ' . $this->conn->error; $status = false; } } return $status; }
public function makeDeterminationCurrent($detId) { $status = 'Determination is now current!'; //Make sure determination data within omoccurrences is in omoccurdeterminations. If already there, INSERT will fail and nothing lost $sqlInsert = 'INSERT INTO omoccurdeterminations(occid, identifiedBy, dateIdentified, sciname, scientificNameAuthorship, ' . 'identificationQualifier, identificationReferences, identificationRemarks, sortsequence) ' . 'SELECT occid, IFNULL(identifiedby,"unknown") AS idby, ' . 'IFNULL(dateidentified,"unknown") AS iddate, sciname, scientificnameauthorship, ' . 'identificationqualifier, identificationreferences, identificationremarks, 10 AS sortseq ' . 'FROM omoccurrences WHERE (occid = ' . $this->occid . ')'; if ($this->conn->query($sqlInsert)) { //Create and insert Symbiota GUID for determination(UUID) $guid = UuidFactory::getUuidV4(); if (!$this->conn->query('INSERT INTO guidoccurdeterminations(guid,detid) VALUES("' . $guid . '",' . $this->conn->insert_id . ')')) { $status .= ' (Warning: Symbiota GUID mapping #1 failed)'; } } //echo "<div>".$sqlInsert."</div>"; //Update omoccurrences to reflect this determination $tid = 0; $sStatus = 0; $family = ''; $sqlTid = 'SELECT t.tid, t.securitystatus, ts.family ' . 'FROM omoccurdeterminations d INNER JOIN taxa t ON d.sciname = t.sciname ' . 'INNER JOIN taxstatus ts ON t.tid = ts.tid ' . 'WHERE (d.detid = ' . $detId . ') AND (taxauthid = 1)'; $rs = $this->conn->query($sqlTid); if ($r = $rs->fetch_object()) { $tid = $r->tid; $family = $r->family; if ($r->securitystatus == 1) { $sStatus = 1; } } $rs->free(); if (!$sStatus && $tid) { $sql2 = 'SELECT c.clid ' . 'FROM fmchecklists c INNER JOIN fmchklsttaxalink cl ON c.clid = cl.clid ' . 'INNER JOIN taxstatus ts1 ON cl.tid = ts1.tid ' . 'INNER JOIN taxstatus ts2 ON ts1.tidaccepted = ts2.tidaccepted ' . 'INNER JOIN omoccurrences o ON c.locality = o.stateprovince ' . 'WHERE c.type = "rarespp" AND ts1.taxauthid = 1 AND ts2.taxauthid = 1 ' . 'AND (ts2.tid = ' . $tid . ') AND (o.occid = ' . $this->occid . ')'; //echo $sql; exit; $rsSs2 = $this->conn->query($sql2); if ($rsSs2->num_rows) { $sStatus = 1; } $rsSs2->free(); } $sqlNewDet = 'UPDATE omoccurrences o INNER JOIN omoccurdeterminations d ON o.occid = d.occid ' . 'SET o.identifiedBy = d.identifiedBy, o.dateIdentified = d.dateIdentified,o.family = ' . ($family ? '"' . $family . '"' : 'NULL') . ',' . 'o.sciname = d.sciname,o.genus = NULL,o.specificEpithet = NULL,o.taxonRank = NULL,o.infraspecificepithet = NULL,o.scientificname = NULL,' . 'o.scientificNameAuthorship = d.scientificnameauthorship,o.identificationQualifier = d.identificationqualifier,' . 'o.identificationReferences = d.identificationreferences,o.identificationRemarks = d.identificationremarks,' . 'o.tidinterpreted = ' . ($tid ? $tid : 'NULL') . ', o.localitysecurity = ' . $sStatus . ' WHERE (detid = ' . $detId . ')'; //echo "<div>".$sqlNewDet."</div>"; $this->conn->query($sqlNewDet); //Set all dets for this specimen to not current $sqlSetCur1 = 'UPDATE omoccurdeterminations SET iscurrent = 0 WHERE occid = ' . $this->occid; if (!$this->conn->query($sqlSetCur1)) { $status = 'ERROR resetting dets to not current: ' . $this->conn->error; //$status .= '; '.$sqlSetCur1; } //Set targetted det to current $sqlSetCur2 = 'UPDATE omoccurdeterminations SET iscurrent = 1 WHERE detid = ' . $detId; if (!$this->conn->query($sqlSetCur2)) { $status = 'ERROR setting target det to current: ' . $this->conn->error; //$status .= '; '.$sqlSetCur2; } if ($tid) { $sql = 'UPDATE images SET tid = ' . $tid . ' WHERE (occid = ' . $this->occid . ')'; //echo $sql; $this->conn->query($sql); } else { $status = 'ERROR: Annotation made current but failed to remap image because taxon name not linked to taxonomic thesaurus.'; } }
public function submitCollAdd($postArr) { global $symbUid; $instCode = $this->cleanInStr($postArr['institutioncode']); $collCode = $this->cleanInStr($postArr['collectioncode']); $coleName = $this->cleanInStr($postArr['collectionname']); $fullDesc = $this->cleanInStr($postArr['fulldescription']); $homepage = $this->cleanInStr($postArr['homepage']); $contact = $this->cleanInStr($postArr['contact']); $email = $this->cleanInStr($postArr['email']); $rights = $this->cleanInStr($postArr['rights']); $rightsHolder = $this->cleanInStr($postArr['rightsholder']); $accessRights = $this->cleanInStr($postArr['accessrights']); $publicEdits = array_key_exists('publicedits', $postArr) ? $postArr['publicedits'] : 0; $guidTarget = array_key_exists('guidtarget', $postArr) ? $postArr['guidtarget'] : ''; if ($_FILES['iconfile']['name']) { $icon = $this->addIconImageFile(); } else { $icon = array_key_exists('iconurl', $postArr) ? $this->cleanInStr($postArr['iconurl']) : ''; } $managementType = array_key_exists('managementtype', $postArr) ? $this->cleanInStr($postArr['managementtype']) : ''; $collType = array_key_exists('colltype', $postArr) ? $this->cleanInStr($postArr['colltype']) : ''; $guid = array_key_exists('collectionguid', $postArr) ? $this->cleanInStr($postArr['collectionguid']) : ''; if (!$guid) { $guid = UuidFactory::getUuidV4(); } $indUrl = array_key_exists('individualurl', $postArr) ? $this->cleanInStr($postArr['individualurl']) : ''; $sortSeq = array_key_exists('sortseq', $postArr) ? $postArr['sortseq'] : ''; $conn = MySQLiConnectionFactory::getCon("write"); $sql = 'INSERT INTO omcollections(institutioncode,collectioncode,collectionname,fulldescription,homepage,' . 'contact,email,latitudedecimal,longitudedecimal,publicedits,guidtarget,rights,rightsholder,accessrights,icon,' . 'managementtype,colltype,collectionguid,individualurl,sortseq) ' . 'VALUES ("' . $instCode . '",' . ($collCode ? '"' . $collCode . '"' : 'NULL') . ',"' . $coleName . '",' . ($fullDesc ? '"' . $fullDesc . '"' : 'NULL') . ',' . ($homepage ? '"' . $homepage . '"' : 'NULL') . ',' . ($contact ? '"' . $contact . '"' : 'NULL') . ',' . ($email ? '"' . $email . '"' : 'NULL') . ',' . ($postArr['latitudedecimal'] ? $postArr['latitudedecimal'] : 'NULL') . ',' . ($postArr['longitudedecimal'] ? $postArr['longitudedecimal'] : 'NULL') . ',' . $publicEdits . ',' . ($guidTarget ? '"' . $guidTarget . '"' : 'NULL') . ',' . ($rights ? '"' . $rights . '"' : 'NULL') . ',' . ($rightsHolder ? '"' . $rightsHolder . '"' : 'NULL') . ',' . ($accessRights ? '"' . $accessRights . '"' : 'NULL') . ',' . ($icon ? '"' . $icon . '"' : 'NULL') . ',' . ($managementType ? '"' . $managementType . '"' : 'Snapshot') . ',' . ($collType ? '"' . $collType . '"' : 'Preserved Specimens') . ',"' . $guid . '",' . ($indUrl ? '"' . $indUrl . '"' : 'NULL') . ',' . ($sortSeq ? $sortSeq : 'NULL') . ') '; //echo "<div>$sql</div>"; $cid = 0; if ($conn->query($sql)) { $cid = $conn->insert_id; $sql = 'INSERT INTO omcollectionstats(collid,recordcnt,uploadedby) ' . 'VALUES(' . $cid . ',0,"' . $symbUid . '")'; $conn->query($sql); //Add collection to category if (isset($postArr['ccpk']) && $postArr['ccpk']) { $sql = 'INSERT INTO omcollcatlink (ccpk,collid) VALUES(' . $postArr['ccpk'] . ',' . $cid . ')'; if (!$conn->query($sql)) { $status = 'ERROR inserting collection category link(2): ' . $conn->error . '; SQL: ' . $sql; return $status; } } $this->collid = $cid; } else { $cid = 'ERROR inserting new collection: ' . $conn->error; } $conn->close(); return $cid; }
public function getEmlDom($emlArr = null) { global $RIGHTS_TERMS_DEFS; $usageTermArr = array(); if (!$emlArr) { $emlArr = $this->getEmlArr(); } foreach ($RIGHTS_TERMS_DEFS as $k => $v) { if ($k == $emlArr['intellectualRights']) { $usageTermArr = $v; } } //Create new DOM document $newDoc = new DOMDocument('1.0', $this->charSetOut); //Add root element $rootElem = $newDoc->createElement('eml:eml'); $rootElem->setAttribute('xmlns:eml', 'eml://ecoinformatics.org/eml-2.1.1'); $rootElem->setAttribute('xmlns:dc', 'http://purl.org/dc/terms/'); $rootElem->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $rootElem->setAttribute('xsi:schemaLocation', 'eml://ecoinformatics.org/eml-2.1.1 http://rs.gbif.org/schema/eml-gbif-profile/1.0.1/eml.xsd'); $rootElem->setAttribute('packageId', UuidFactory::getUuidV4()); $rootElem->setAttribute('system', 'http://symbiota.org'); $rootElem->setAttribute('scope', 'system'); $rootElem->setAttribute('xml:lang', 'eng'); $newDoc->appendChild($rootElem); $cArr = array(); $datasetElem = $newDoc->createElement('dataset'); $rootElem->appendChild($datasetElem); if (array_key_exists('alternateIdentifier', $emlArr)) { foreach ($emlArr['alternateIdentifier'] as $v) { $altIdElem = $newDoc->createElement('alternateIdentifier'); $altIdElem->appendChild($newDoc->createTextNode($v)); $datasetElem->appendChild($altIdElem); } } if (array_key_exists('title', $emlArr)) { $titleElem = $newDoc->createElement('title'); $titleElem->setAttribute('xml:lang', 'eng'); $titleElem->appendChild($newDoc->createTextNode($emlArr['title'])); $datasetElem->appendChild($titleElem); } if (array_key_exists('creator', $emlArr)) { $createArr = $emlArr['creator']; foreach ($createArr as $childArr) { $creatorElem = $newDoc->createElement('creator'); if (isset($childArr['attr'])) { $attrArr = $childArr['attr']; unset($childArr['attr']); foreach ($attrArr as $atKey => $atValue) { $creatorElem->setAttribute($atKey, $atValue); } } foreach ($childArr as $k => $v) { $newChildElem = $newDoc->createElement($k); $newChildElem->appendChild($newDoc->createTextNode($v)); $creatorElem->appendChild($newChildElem); } $datasetElem->appendChild($creatorElem); } } if (array_key_exists('metadataProvider', $emlArr)) { $mdArr = $emlArr['metadataProvider']; foreach ($mdArr as $childArr) { $mdElem = $newDoc->createElement('metadataProvider'); foreach ($childArr as $k => $v) { $newChildElem = $newDoc->createElement($k); $newChildElem->appendChild($newDoc->createTextNode($v)); $mdElem->appendChild($newChildElem); } $datasetElem->appendChild($mdElem); } } if (array_key_exists('pubDate', $emlArr) && $emlArr['pubDate']) { $pubElem = $newDoc->createElement('pubDate'); $pubElem->appendChild($newDoc->createTextNode($emlArr['pubDate'])); $datasetElem->appendChild($pubElem); } $langStr = 'eng'; if (array_key_exists('language', $emlArr) && $emlArr) { $langStr = $emlArr['language']; } $langElem = $newDoc->createElement('language'); $langElem->appendChild($newDoc->createTextNode($langStr)); $datasetElem->appendChild($langElem); if (array_key_exists('description', $emlArr) && $emlArr['description']) { $abstractElem = $newDoc->createElement('abstract'); $paraElem = $newDoc->createElement('para'); $paraElem->appendChild($newDoc->createTextNode($emlArr['description'])); $abstractElem->appendChild($paraElem); $datasetElem->appendChild($abstractElem); } if (array_key_exists('contact', $emlArr)) { $contactArr = $emlArr['contact']; $contactElem = $newDoc->createElement('contact'); $addrArr = array(); if (isset($contactArr['addr'])) { $addrArr = $contactArr['addr']; unset($contactArr['addr']); } foreach ($contactArr as $contactKey => $contactValue) { $conElem = $newDoc->createElement($contactKey); $conElem->appendChild($newDoc->createTextNode($contactValue)); $contactElem->appendChild($conElem); } if (isset($contactArr['addr'])) { $addressElem = $newDoc->createElement('address'); foreach ($addrArr as $aKey => $aVal) { $childAddrElem = $newDoc->createElement($aKey); $childAddrElem->appendChild($newDoc->createTextNode($aVal)); $addressElem->appendChild($childAddrElem); } $contactElem->appendChild($addressElem); } $datasetElem->appendChild($contactElem); } if (array_key_exists('associatedParty', $emlArr)) { $associatedPartyArr = $emlArr['associatedParty']; foreach ($associatedPartyArr as $assocKey => $assocArr) { $assocElem = $newDoc->createElement('associatedParty'); $addrArr = array(); if (isset($assocArr['address'])) { $addrArr = $assocArr['address']; unset($assocArr['address']); } foreach ($assocArr as $aKey => $aArr) { $childAssocElem = $newDoc->createElement($aKey); $childAssocElem->appendChild($newDoc->createTextNode($aArr)); $assocElem->appendChild($childAssocElem); } if ($addrArr) { $addrElem = $newDoc->createElement('address'); foreach ($addrArr as $addrKey => $addrValue) { $childAddrElem = $newDoc->createElement($addrKey); $childAddrElem->appendChild($newDoc->createTextNode($addrValue)); $addrElem->appendChild($childAddrElem); } $assocElem->appendChild($addrElem); } $datasetElem->appendChild($assocElem); } } if (array_key_exists('intellectualRights', $emlArr)) { $rightsElem = $newDoc->createElement('intellectualRights'); $paraElem = $newDoc->createElement('para'); $paraElem->appendChild($newDoc->createTextNode('To the extent possible under law, the publisher has waived all rights to these data and has dedicated them to the')); $ulinkElem = $newDoc->createElement('ulink'); $citetitleElem = $newDoc->createElement('citetitle'); $citetitleElem->appendChild($newDoc->createTextNode(array_key_exists('title', $usageTermArr) ? $usageTermArr['title'] : '')); $ulinkElem->appendChild($citetitleElem); $ulinkElem->setAttribute('url', array_key_exists('url', $usageTermArr) ? $usageTermArr['url'] : $emlArr['intellectualRights']); $paraElem->appendChild($ulinkElem); $paraElem->appendChild($newDoc->createTextNode(array_key_exists('def', $usageTermArr) ? $usageTermArr['def'] : '')); $rightsElem->appendChild($paraElem); $datasetElem->appendChild($rightsElem); } $symbElem = $newDoc->createElement('symbiota'); $dateElem = $newDoc->createElement('dateStamp'); $dateElem->appendChild($newDoc->createTextNode(date("c"))); $symbElem->appendChild($dateElem); //Citation $id = UuidFactory::getUuidV4(); $citeElem = $newDoc->createElement('citation'); $citeElem->appendChild($newDoc->createTextNode($GLOBALS['defaultTitle'] . ' - ' . $id)); $citeElem->setAttribute('identifier', $id); $symbElem->appendChild($citeElem); //Physical $physicalElem = $newDoc->createElement('physical'); $physicalElem->appendChild($newDoc->createElement('characterEncoding', $this->charSetOut)); //format $dfElem = $newDoc->createElement('dataFormat'); $edfElem = $newDoc->createElement('externallyDefinedFormat'); $dfElem->appendChild($edfElem); $edfElem->appendChild($newDoc->createElement('formatName', 'Darwin Core Archive')); $physicalElem->appendChild($dfElem); $symbElem->appendChild($physicalElem); //Collection data if (array_key_exists('collMetadata', $emlArr)) { foreach ($emlArr['collMetadata'] as $k => $collArr) { $collArr = $this->utf8EncodeArr($collArr); $collElem = $newDoc->createElement('collection'); if (isset($collArr['attr']) && $collArr['attr']) { $attrArr = $collArr['attr']; unset($collArr['attr']); foreach ($attrArr as $attrKey => $attrValue) { $collElem->setAttribute($attrKey, $attrValue); } } $abstractStr = ''; if (isset($collArr['abstract']) && $collArr['abstract']) { $abstractStr = $collArr['abstract']; unset($collArr['abstract']); } foreach ($collArr as $collKey => $collValue) { $collElem2 = $newDoc->createElement($collKey); $collElem2->appendChild($newDoc->createTextNode($collValue)); $collElem->appendChild($collElem2); } if ($abstractStr) { $abstractElem = $newDoc->createElement('abstract'); $abstractElem2 = $newDoc->createElement('para'); $abstractElem2->appendChild($newDoc->createTextNode($abstractStr)); $abstractElem->appendChild($abstractElem2); $collElem->appendChild($abstractElem); } $symbElem->appendChild($collElem); } } $metaElem = $newDoc->createElement('metadata'); $metaElem->appendChild($symbElem); if ($this->schemaType == 'coge' && $this->geolocateVariables) { if (!$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) { $this->serverDomain .= ':' . $_SERVER["SERVER_PORT"]; } } $urlPathPrefix = ''; if ($this->serverDomain) { $urlPathPrefix = $this->serverDomain . $GLOBALS['CLIENT_ROOT'] . (substr($GLOBALS['CLIENT_ROOT'], -1) == '/' ? '' : '/'); $urlPathPrefix .= 'collections/individual/index.php'; //Add Geolocate metadata $glElem = $newDoc->createElement('geoLocate'); $glElem->appendChild($newDoc->createElement('dataSourcePrimaryName', $this->geolocateVariables['cogename'])); $glElem->appendChild($newDoc->createElement('dataSourceSecondaryName', $this->geolocateVariables['cogedescr'])); $glElem->appendChild($newDoc->createElement('targetCommunityName', $this->geolocateVariables['cogecomm'])); #if(isset($this->geolocateVariables['targetcommunityidentifier'])) $glElem->appendChild($newDoc->createElement('targetCommunityIdentifier','')); $glElem->appendChild($newDoc->createElement('specimenHyperlinkBase', $urlPathPrefix)); $glElem->appendChild($newDoc->createElement('specimenHyperlinkParameter', 'occid')); $glElem->appendChild($newDoc->createElement('specimenHyperlinkValueField', 'Id')); $metaElem->appendChild($glElem); } } $addMetaElem = $newDoc->createElement('additionalMetadata'); $addMetaElem->appendChild($metaElem); $rootElem->appendChild($addMetaElem); return $newDoc; }
public function addOccurrence($occArr) { $status = "SUCCESS: new occurrence record submitted successfully "; if ($occArr) { $fieldArr = array('basisOfRecord' => 's', 'catalogNumber' => 's', 'otherCatalogNumbers' => 's', 'occurrenceid' => 's', 'ownerInstitutionCode' => 's', 'family' => 's', 'sciname' => 's', 'tidinterpreted' => 'n', 'scientificNameAuthorship' => 's', 'identifiedBy' => 's', 'dateIdentified' => 's', 'identificationReferences' => 's', 'identificationremarks' => 's', 'taxonRemarks' => 's', 'identificationQualifier' => 's', 'typeStatus' => 's', 'recordedBy' => 's', 'recordNumber' => 's', 'associatedCollectors' => 's', 'eventDate' => 'd', 'year' => 'n', 'month' => 'n', 'day' => 'n', 'startDayOfYear' => 'n', 'endDayOfYear' => 'n', 'verbatimEventDate' => 's', 'habitat' => 's', 'substrate' => 's', 'fieldnumber' => 's', 'occurrenceRemarks' => 's', 'associatedTaxa' => 's', 'verbatimattributes' => 's', 'dynamicProperties' => 's', 'reproductiveCondition' => 's', 'cultivationStatus' => 's', 'establishmentMeans' => 's', 'lifestage' => 's', 'sex' => 's', 'individualcount' => 's', 'samplingprotocol' => 's', 'preparations' => 's', 'country' => 's', 'stateProvince' => 's', 'county' => 's', 'municipality' => 's', 'locality' => 's', 'localitySecurity' => 'n', 'localitysecurityreason' => 's', 'decimalLatitude' => 'n', 'decimalLongitude' => 'n', 'geodeticDatum' => 's', 'coordinateUncertaintyInMeters' => 'n', 'verbatimCoordinates' => 's', 'footprintwkt' => 's', 'georeferencedBy' => 's', 'georeferenceProtocol' => 's', 'georeferenceSources' => 's', 'georeferenceVerificationStatus' => 's', 'georeferenceRemarks' => 's', 'minimumElevationInMeters' => 'n', 'maximumElevationInMeters' => 'n', 'verbatimElevation' => 's', 'disposition' => 's', 'language' => 's', 'duplicateQuantity' => 'n', 'labelProject' => 's', 'processingstatus' => 's', 'recordEnteredBy' => 's', 'observeruid' => 'n', 'dateentered' => 'd', 'genericcolumn2' => 's'); $sql = 'INSERT INTO omoccurrences(collid, ' . implode(array_keys($fieldArr), ',') . ') ' . 'VALUES (' . $occArr["collid"]; $fieldArr = array_change_key_case($fieldArr); if (array_key_exists('cultivationstatus', $occArr)) { $occArr['cultivationstatus'] = '1'; } if (array_key_exists('localitysecurity', $occArr)) { $occArr['localitysecurity'] = '1'; } if (!isset($occArr['dateentered']) || !$occArr['dateentered']) { $occArr['dateentered'] = date('Y-m-d H:i:s'); } if (!isset($occArr['basisofrecord']) || !$occArr['basisofrecord']) { $occArr['basisofrecord'] = strpos($this->collMap['colltype'], 'Observations') !== false ? 'HumanObservation' : 'PreservedSpecimen'; } //Temp code for WeDigBio date entry event $occArr['genericcolumn2'] = $_SERVER['REMOTE_ADDR']; /////////////////// foreach ($fieldArr as $fieldStr => $fieldType) { $fieldValue = ''; if (array_key_exists($fieldStr, $occArr)) { $fieldValue = $occArr[$fieldStr]; } if ($fieldValue) { if ($fieldType == 'n') { if (is_numeric($fieldValue)) { $sql .= ', ' . $fieldValue; } else { $sql .= ', NULL'; } } else { //Is string or date $sql .= ', "' . $this->cleanInStr($fieldValue) . '"'; } } else { $sql .= ', NULL'; } } $sql .= ')'; //echo "<div>".$sql."</div>"; if ($this->conn->query($sql)) { $this->occid = $this->conn->insert_id; //Update collection stats $this->conn->query('UPDATE omcollectionstats SET recordcnt = recordcnt + 1 WHERE collid = ' . $this->collId); //Create and insert Symbiota GUID (UUID) $guid = UuidFactory::getUuidV4(); if (!$this->conn->query('INSERT INTO guidoccurrences(guid,occid) VALUES("' . $guid . '",' . $this->occid . ')')) { $status .= '(WARNING: Symbiota GUID mapping failed) '; } //deal with Exsiccati, if applicable if (isset($occArr['ometid']) && isset($occArr['exsnumber'])) { //If exsiccati titie is submitted, trim off first character that was used to force Google Chrom to sort correctly $ometid = $this->cleanInStr($occArr['ometid']); $exsNumber = $this->cleanInStr($occArr['exsnumber']); if ($ometid && $exsNumber) { $exsNumberId = ''; $sql = 'SELECT omenid FROM omexsiccatinumbers WHERE ometid = ' . $ometid . ' AND exsnumber = "' . $exsNumber . '"'; $rs = $this->conn->query($sql); if ($r = $rs->fetch_object()) { $exsNumberId = $r->omenid; } $rs->free(); if (!$exsNumberId) { //There is no exsnumber for that title, thus lets add it and record exsomenid $sqlNum = 'INSERT INTO omexsiccatinumbers(ometid,exsnumber) ' . 'VALUES(' . $ometid . ',"' . $exsNumber . '")'; if ($this->conn->query($sqlNum)) { $exsNumberId = $this->conn->insert_id; } else { $status .= '(WARNING adding exsiccati number: ' . $this->conn->error . ') '; } } if ($exsNumberId) { //Add exsiccati $sql1 = 'INSERT INTO omexsiccatiocclink(omenid, occid) ' . 'VALUES(' . $exsNumberId . ',' . $this->occid . ')'; if (!$this->conn->query($sql1)) { $status .= '(WARNING adding exsiccati: ' . $this->conn->error . ') '; } } } } //Deal with checklist voucher if (isset($occArr['clidvoucher']) && $occArr['clidvoucher']) { if (isset($occArr['tidinterpreted']) && $occArr['tidinterpreted']) { //Check to see it the name is in the list, if not, add it $clTid = 0; $sqlCl = 'SELECT cl.tid ' . 'FROM fmchklsttaxalink cl INNER JOIN taxstatus ts1 ON cl.tid = ts1.tidaccepted ' . 'INNER JOIN taxstatus ts2 ON ts1.tidaccepted = ts2.tidaccepted ' . 'WHERE ts1.taxauthid = 1 AND ts2.taxauthid = 1 AND ts2.tid = ' . $occArr['tidinterpreted'] . ' AND cl.clid = ' . $occArr['clidvoucher']; $rsCl = $this->conn->query($sqlCl); //echo $sqlCl; if ($rowCl = $rsCl->fetch_object()) { $clTid = $rowCl->tid; } $rsCl->free(); if (!$clTid) { $sqlCl1 = 'INSERT INTO fmchklsttaxalink(clid, tid) VALUES(' . $occArr['clidvoucher'] . ',' . $occArr['tidinterpreted'] . ') '; if ($this->conn->query($sqlCl1)) { $clTid = $occArr['tidinterpreted']; } else { $status .= '(WARNING adding scientific name to checklist: ' . $this->conn->error . ') '; } } //Add voucher if ($clTid) { $sqlCl2 = 'INSERT INTO fmvouchers(occid,clid,tid) ' . 'values(' . $this->occid . ',' . $occArr['clidvoucher'] . ',' . $clTid . ')'; //echo $sqlCl2; if (!$this->conn->query($sqlCl2)) { $status .= '(WARNING adding voucher link: ' . $this->conn->error . ') '; } } } } //Deal with duplicate clustering if (isset($occArr['linkdupe']) && $occArr['linkdupe']) { $dupTitle = $occArr['recordedby'] . ' ' . $occArr['recordnumber'] . ' ' . $occArr['eventdate']; $status .= $this->linkDuplicates($occArr['linkdupe'], $dupTitle); } } else { $status = "ERROR - failed to add occurrence record: " . $this->conn->error . '<br/>SQL: ' . $sql; } } return $status; }
/** Function save() will either save the current record or insert a new record. * Inserts new record if the primary key field in this table is null for this * instance of this object. * Otherwise updates the record identified by the primary key value of the * current instance. * @return true on success, false on failure */ public function save() { global $SYMB_UID; $this->emptyWrongTypeValues(); // sanity check, make sure that this is not an attempt to save an agent with no name. if (strlen(trim($this->getnamestring() . $this->getfamilyname() . $this->getfirstname() . $this->getmiddlename())) == 0) { $this->error = "Error: Unable to save. Agent lacks a name."; return false; } if (strlen($this->yearofdeath) > 0 && $this->living == 'Y') { $this->error = "Error: Unable to save. Agent has a year of death and is also living."; return false; } $returnvalue = false; $this->setlastmodifiedbyuid($SYMB_UID); // Test to see if this is an insert or update. if ($this->agentid != NULL) { $sql = 'UPDATE agents SET '; $isInsert = false; $sql .= "familyname = ? "; $sql .= ", firstname = ? "; $sql .= ", middlename = ? "; $sql .= ", startyearactive = ? "; $sql .= ", endyearactive = ? "; $sql .= ", notes = ? "; $sql .= ", rating = ? "; $sql .= ", guid = ? "; if (strlen($this->preferredrecbyid) == 0) { $sql .= ", preferredrecbyid = null "; } else { $sql .= ", preferredrecbyid = ? "; } $sql .= ", biography = ? "; $sql .= ", taxonomicgroups = ? "; $sql .= ", collectionsat = ? "; $sql .= ", curated = ? "; $sql .= ", nototherwisespecified = ? "; $sql .= ", datelastmodified = now() "; $sql .= ", lastmodifiedbyuid = ? "; $sql .= ", type = ? "; $sql .= ", namestring = ? "; $sql .= ", prefix = ? "; $sql .= ", suffix = ? "; $sql .= ", yearofbirth = ? "; $sql .= ", yearofdeath = ? "; $sql .= ", yearofbirthmodifier = ? "; $sql .= ", yearofdeathmodifier = ? "; $sql .= ", mbox_sha1sum = ? "; $sql .= ", uuid = ? "; $sql .= ", living = ? "; $sql .= " WHERE agentid = ? "; } else { $sql = 'INSERT INTO agents '; $isInsert = true; $sql .= '( familyname , firstname , middlename , startyearactive , endyearactive , notes , rating , guid , preferredrecbyid , biography , taxonomicgroups , collectionsat , curated , nototherwisespecified , datelastmodified , lastmodifiedbyuid , type , namestring , prefix , suffix , yearofbirth , yearofdeath , yearofbirthmodifier, yearofdeathmodifier, mbox_sha1sum , uuid, living ) VALUES ('; $sql .= " ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; // guid if (strlen($this->preferredrecbyid) == 0) { $sql .= " , null "; } else { $sql .= " , ? "; } $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , now() "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= " , ? "; $sql .= ')'; if (strlen($this->uuid) == 0) { $uf = new UuidFactory(); $this->setuuid($uf->getUuidV4()); } } if ($statement = $this->conn->prepare($sql)) { // update if ($this->agentid != NULL) { if (strlen($this->preferredrecbyid) == 0) { $statement->bind_param("sssiisissssiiissssiisssssi", $this->familyname, $this->firstname, $this->middlename, $this->startyearactive, $this->endyearactive, $this->notes, $this->rating, $this->guid, $this->biography, $this->taxonomicgroups, $this->collectionsat, $this->curated, $this->nototherwisespecified, $this->lastmodifiedbyuid, $this->type, $this->namestring, $this->prefix, $this->suffix, $this->yearofbirth, $this->yearofdeath, $this->yearofbirthmodifier, $this->yearofdeathmodifier, $this->mbox_sha1sum, $this->uuid, $this->living, $this->agentid); } else { $statement->bind_param("sssiisisisssiiissssiisssssi", $this->familyname, $this->firstname, $this->middlename, $this->startyearactive, $this->endyearactive, $this->notes, $this->rating, $this->guid, $this->preferredrecbyid, $this->biography, $this->taxonomicgroups, $this->collectionsat, $this->curated, $this->nototherwisespecified, $this->lastmodifiedbyuid, $this->type, $this->namestring, $this->prefix, $this->suffix, $this->yearofbirth, $this->yearofdeath, $this->yearofbirthmodifier, $this->yearofdeathmodifier, $this->mbox_sha1sum, $this->uuid, $this->living, $this->agentid); } } else { // insert if (strlen($this->preferredrecbyid) == 0) { $statement->bind_param("sssiisissssiiissssiisssss", $this->familyname, $this->firstname, $this->middlename, $this->startyearactive, $this->endyearactive, $this->notes, $this->rating, $this->guid, $this->biography, $this->taxonomicgroups, $this->collectionsat, $this->curated, $this->nototherwisespecified, $this->lastmodifiedbyuid, $this->type, $this->namestring, $this->prefix, $this->suffix, $this->yearofbirth, $this->yearofdeath, $this->yearofbirthmodifier, $this->yearofdeathmodifier, $this->mbox_sha1sum, $this->uuid, $this->living); } else { $statement->bind_param("sssiisisisssiiissssiisssss", $this->familyname, $this->firstname, $this->middlename, $this->startyearactive, $this->endyearactive, $this->notes, $this->rating, $this->guid, $this->preferredrecbyid, $this->biography, $this->taxonomicgroups, $this->collectionsat, $this->curated, $this->nototherwisespecified, $this->lastmodifiedbyuid, $this->type, $this->namestring, $this->prefix, $this->suffix, $this->yearofbirth, $this->yearofdeath, $this->yearofbirthmodifier, $this->yearofdeathmodifier, $this->mbox_sha1sum, $this->uuid, $this->living); } } $statement->execute(); $rows = $statement->affected_rows; if ($rows !== 1) { $this->error = $statement->error; } else { if ($this->agentid == NULL) { // obtain the primary key value set bh the insert statement. $this->setagentid($this->conn->insert_id); } } $statement->close(); } else { $this->error = mysqli_error($this->conn); } if ($this->error == '') { $returnvalue = true; } $this->loaded = true; return $returnvalue; }