function build_postcard_mods_data($repository, $postcardData)
{
    $mods = "<?xml version=\"1.0\"?>";
    $mods .= "<mods xmlns=\"http://www.loc.gov/mods/v3\" xmlns:marmot=\"http://marmot.org/local_mods_extension\" xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
    $mods .= "<titleInfo>\r\n";
    $mods .= "<title>" . htmlspecialchars($postcardData['title']) . "</title>\r\n";
    $mods .= "</titleInfo>\r\n";
    $mods .= "<mods:genre>postcard</mods:genre>\r\n";
    $mods .= "<identifier>" . htmlspecialchars($postcardData['acsnId']) . "</identifier>\r\n";
    $mods .= "<identifier>" . htmlspecialchars($postcardData['itemId']) . "</identifier>\r\n";
    if (strlen($postcardData['dateCreated']) > 0) {
        $mods .= "<originInfo>\r\n";
        $qualifer = '';
        if (preg_match('/ca./', $postcardData['dateCreated'])) {
            $qualifer = 'approximate';
            $postcardData['dateCreated'] = trim(str_replace('ca.', '', $postcardData['dateCreated']));
        } elseif (preg_match('/circa/', $postcardData['dateCreated'])) {
            $qualifer = 'approximate';
            $postcardData['dateCreated'] = trim(str_replace('circa', '', $postcardData['dateCreated']));
        } elseif (preg_match("/'s/", $postcardData['dateCreated'])) {
            $qualifer = 'approximate';
            $postcardData['dateCreated'] = trim(str_replace("'s", '', $postcardData['dateCreated']));
        } elseif (preg_match('/\\d{4}s/', $postcardData['dateCreated'])) {
            $qualifer = 'approximate';
            $postcardData['dateCreated'] = trim(str_replace("s", '', $postcardData['dateCreated']));
        }
        if (preg_match('/^([\\d-]+)\\/([\\d-]+)$/', $postcardData['dateCreated'], $matches)) {
            $mods .= "<dateCreated point='start' qualifier='{$qualifer}'>" . htmlspecialchars($matches[1]) . "</dateCreated>\r\n";
            $mods .= "<dateCreated point='end' qualifier='{$qualifer}'>" . htmlspecialchars($matches[2]) . "</dateCreated>\r\n";
        } elseif (preg_match('/^\\d+\\/\\d+\\/\\d+$/', $postcardData['dateCreated'], $matches)) {
            $mods .= "<dateCreated point='start' qualifier='{$qualifer}'>" . htmlspecialchars($postcardData['dateCreated']) . "</dateCreated>\r\n";
        } elseif (preg_match('/^\\d+-\\d+-\\d+$/', $postcardData['dateCreated'], $matches)) {
            $mods .= "<dateCreated point='start' qualifier='{$qualifer}'>" . htmlspecialchars($postcardData['dateCreated']) . "</dateCreated>\r\n";
        } elseif (preg_match('/^(\\d{4})-(\\d{4})$/', $postcardData['dateCreated'], $matches)) {
            $mods .= "<dateCreated point='start' qualifier='{$qualifer}'>" . htmlspecialchars($matches[1]) . "</dateCreated>\r\n";
            $mods .= "<dateCreated point='end' qualifier='{$qualifer}'>" . htmlspecialchars($matches[2]) . "</dateCreated>\r\n";
        } else {
            $mods .= "<dateCreated point='start' qualifier='{$qualifer}'>" . htmlspecialchars($postcardData['dateCreated']) . "</dateCreated>\r\n";
        }
        $mods .= "</originInfo>\r\n";
    }
    $mods .= "<abstract>" . htmlspecialchars($postcardData['description']) . "</abstract>\r\n";
    $allSubjects = array();
    foreach ($postcardData['lc_subjects'] as $fullSubject) {
        $subjectParts = explode('|', $fullSubject);
        //Always add the first part of the subject |a
        //$allSubjects[$subjectParts[0]] = $subjectParts[0];
        $fullSubject = $subjectParts[0];
        for ($i = 1; $i < count($subjectParts); $i++) {
            $subjectWithoutIndicator = substr($subjectParts[$i], 1);
            $subfield = substr($subjectParts[$i], 0, 1);
            switch ($subfield) {
                case 'z':
                    //Ignore geographic portions of the LC subject since we have that as part of related entity
                    break;
                case 'v':
                    //Add form
                //Add form
                case 'x':
                    //Add general subdivision
                    $subjectWithForm = $subjectParts[0] . ' -- ' . $subjectWithoutIndicator;
                    $fullSubject .= ' -- ' . $subjectWithoutIndicator;
                    $allSubjects[$subjectWithForm] = $subjectWithForm;
                    break;
                default:
                    echo "Unhandled subdivision {$subfield}";
            }
        }
        $allSubjects[$fullSubject] = $fullSubject;
    }
    foreach ($allSubjects as $subject) {
        $mods .= "<subject authority='lcsh'>\r\n";
        $mods .= "<topic>" . htmlspecialchars($subject) . "</topic>\r\n";
        $mods .= "</subject>\r\n";
    }
    $mods .= "<language>\r\n";
    $mods .= "<languageTerm authority='iso639-2b' type='code'>English</languageTerm>\r\n";
    $mods .= "</language>\r\n";
    $mods .= "<physicalDescription>\r\n";
    $mods .= "<extent>" . htmlspecialchars($postcardData['itemName']) . "</extent>\r\n";
    $mods .= "<form type='material'>" . htmlspecialchars($postcardData['medium']) . "</form>\r\n";
    $mods .= "</physicalDescription>\r\n";
    $mods .= "<physicalLocation>" . htmlspecialchars($postcardData['volumeNumber'] . ' ' . $postcardData['photoNumber']) . "</physicalLocation>\r\n";
    $mods .= "<extension>\r\n";
    $mods .= "<marmot:marmotLocal>\r\n";
    $mods .= "<marmot:correspondence>\r\n";
    $mods .= "<marmot:postcardPublisherNumber>" . htmlspecialchars($postcardData['pubPhotoNumber']) . "</marmot:postcardPublisherNumber>\r\n";
    $mods .= "</marmot:correspondence>\r\n";
    foreach ($postcardData['creators'] as $creator) {
        //reverse firstname and last name for people
        $creatorNameNormalized = trim($creator['name']);
        if (stripos($creator['type'], 'person') !== false) {
            if (strpos($creatorNameNormalized, ',') > 0) {
                $names = explode(',', $creatorNameNormalized, 2);
                $creatorNameNormalized = trim($names[1] . ' ' . $names[0]);
            }
        }
        $entityPID = doesEntityExist($creatorNameNormalized);
        //If entity does not exist, we should create it
        if ($entityPID == false) {
            if (stripos($creator['type'], 'person') !== false) {
                $entityPID = createPerson($repository, $creatorNameNormalized);
            } else {
                $entityPID = createOrganization($repository, $creatorNameNormalized);
            }
        }
        if (stripos($creator['type'], 'donor') !== false) {
            $mods .= "<marmot:relatedPersonOrg>\r\n";
            $mods .= "<marmot:role>donor</marmot:role>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:relatedPersonOrg>\r\n";
        } elseif (stripos($creator['type'], 'photographer') !== false) {
            $mods .= "<marmot:hasCreator role='photographer'>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:hasCreator>\r\n";
        } elseif (stripos($creator['type'], 'artist') !== false) {
            $mods .= "<marmot:hasCreator role='artist'>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:hasCreator>\r\n";
        } elseif (stripos($creator['type'], 'author') !== false) {
            $mods .= "<marmot:hasCreator role='author'>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:hasCreator>\r\n";
        } elseif (stripos($creator['type'], 'owner') !== false) {
            $mods .= "<marmot:relatedPersonOrg>\r\n";
            $mods .= "<marmot:role>owner</marmot:role>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:relatedPersonOrg>\r\n";
        } elseif (stripos($creator['type'], 'publisher') !== false) {
            $mods .= "<marmot:relatedPersonOrg>\r\n";
            $mods .= "<marmot:role>publisher</marmot:role>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:relatedPersonOrg>\r\n";
        } elseif (stripos($creator['type'], 'producer') !== false) {
            $mods .= "<marmot:hasCreator role='producer'>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:hasCreator>\r\n";
        } else {
            echo "Unhandled creator type " . $creator['type'];
        }
    }
    foreach ($postcardData['related_people'] as $person) {
        $creatorNameNormalized = $person;
        if (strpos($creatorNameNormalized, ',') > 0) {
            $names = explode(',', $creatorNameNormalized, 2);
            $creatorNameNormalized = trim($names[1] . ' ' . $names[0]);
        }
        $entityPID = doesEntityExist($creatorNameNormalized);
        //If entity does not exist, we should create it
        if ($entityPID == false) {
            $entityPID = createPerson($repository, $creatorNameNormalized);
        }
        $mods .= "<marmot:relatedPersonOrg>\r\n";
        $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
        $mods .= "<marmot:entityTitle>" . htmlspecialchars($creatorNameNormalized) . "</marmot:entityTitle>\r\n";
        $mods .= "</marmot:relatedPersonOrg>\r\n";
    }
    foreach ($postcardData['related_organizations'] as $organization) {
        $entityPID = doesEntityExist($organization);
        //If entity does not exist, we should create it
        if ($entityPID == false) {
            $entityPID = createOrganization($repository, $organization);
        }
        $mods .= "<marmot:picturedEntity>\r\n";
        $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
        $mods .= "<marmot:entityTitle>" . htmlspecialchars($organization) . "</marmot:entityTitle>\r\n";
        $mods .= "</marmot:picturedEntity>\r\n";
    }
    foreach ($postcardData['geo_place_ids'] as $placeId) {
        //Find the place in solr based on information entered as external data
        //mods_extension_marmotLocal_externalLink_fortLewisGeoPlaces_link_mlt
        list($entityPID, $title) = findPlaceByFortLewisId($placeId);
        if ($entityPID != false) {
            $mods .= "<marmot:picturedEntity>\r\n";
            $mods .= "<marmot:entityPid>{$entityPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($title) . "</marmot:entityTitle>\r\n";
            $mods .= "</marmot:picturedEntity>\r\n";
        }
    }
    $mods .= "<marmot:pikaOptions>\r\n";
    $mods .= "<marmot:includeInPika>yes</marmot:includeInPika>\r\n";
    $mods .= "<marmot:showInSearchResults>yes</marmot:showInSearchResults>\r\n";
    $mods .= "</marmot:pikaOptions>\r\n";
    $mods .= "</marmot:marmotLocal>\r\n";
    $mods .= "</extension>\r\n";
    $mods .= "<mods:accessCondition>\r\n";
    $mods .= "<marmot:rightsStatement>\r\n";
    $mods .= "The Center of Southwest Studies is not aware of any U.S. copyright or any other restrictions in the postcards in this collection.  However, some of the content may be protected by the U.S.  Copyright Law (Title 17, U.S.C.) and/or by the copyright or neighboring-rights laws of other nations.  Additionally, the reproduction of some materials may be restricted by privacy and/or publicity rights.";
    $mods .= "</marmot:rightsStatement>\r\n";
    $mods .= "</mods:accessCondition>\r\n";
    $mods .= "</mods>";
    return $mods;
}
             }
         }
         $i++;
     }
 }
 //Find each place within the export & add to Islandora
 if ($loadPlaces) {
     $places = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->place);
     foreach ($places as $place) {
         $place = trim($place);
         if (strlen($place) == 0) {
             continue;
         }
         //Check to see if the entity exists already
         $new = false;
         $existingPID = doesEntityExist($place);
         if ($existingPID != false) {
             if (!$updateModsForExistingEntities) {
                 continue;
             }
             //Load the object
             $entity = $repository->getObject($existingPID);
         } else {
             //Create an entity within Islandora
             $entity = $repository->constructObject('place');
             $entity->models = array('islandora:placeCModel');
             $entity->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'marmot:places');
             $entity->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:entity_collection');
             $new = true;
         }
         echo "{$i}) Processing Place {$place} <br/>";
/**
 * @param string $title
 * @param SimpleXMLElement $exportedItem
 */
function build_evld_mods_data($title, $exportedItem)
{
    $mods = "<?xml version=\"1.0\"?>";
    $mods .= "<mods xmlns=\"http://www.loc.gov/mods/v3\" xmlns:marmot=\"http://marmot.org/local_mods_extension\" xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
    /*if (isset($exportedItem->collection)){
    		$mods .= "<relatedItem>{$exportedItem->collection}</relatedItem>";
    	}
    	if (isset($exportedItem->homeloc)){
    		$mods .= "<relatedItem>{$exportedItem->homeloc}</relatedItem>";
    	}*/
    $mods .= "<titleInfo>\r\n";
    $mods .= "<title>" . htmlspecialchars($title) . "</title>\r\n";
    $mods .= "<subTitle>" . htmlspecialchars($exportedItem->caption) . "</subTitle>\r\n";
    $mods .= "</titleInfo>\r\n";
    $mods .= "<identifier>" . htmlspecialchars($exportedItem->objectid) . "</identifier>\r\n";
    $mods .= "<part>" . htmlspecialchars($exportedItem->imageno) . "</part>\r\n";
    $mods .= "<abstract>" . htmlspecialchars($exportedItem->descrip) . "</abstract>\r\n";
    $mods .= "<subject authority='local'>\r\n";
    $classes = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->classes);
    foreach ($classes as $class) {
        $mods .= "<topic>" . htmlspecialchars($class) . "</topic>\r\n";
    }
    $mods .= "</subject>\r\n";
    $mods .= "<subject authority='local'>\r\n";
    $sterms = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->sterms);
    foreach ($sterms as $sterm) {
        $mods .= "<topic>" . htmlspecialchars($sterm) . "</topic>\r\n";
    }
    $mods .= "</subject>\r\n";
    $mods .= "<subject authority='local'>\r\n";
    $subjects = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->subjects);
    foreach ($subjects as $subject) {
        $mods .= "<topic>" . htmlspecialchars($subject) . "</topic>\r\n";
    }
    $mods .= "</subject>\r\n";
    $mods .= "<originInfo>\r\n";
    $mods .= "<dateCreated>" . htmlspecialchars($exportedItem->date) . "</dateCreated>\r\n";
    $mods .= "<dateCreated point='start'>" . htmlspecialchars($exportedItem->earlydate) . "</dateCreated>\r\n";
    $mods .= "<dateCreated point='end'>" . htmlspecialchars($exportedItem->latedate) . "</dateCreated>\r\n";
    $mods .= "</originInfo>\r\n";
    $mods .= "<recordInfo>\r\n";
    $mods .= "<recordOrigin>" . htmlspecialchars($exportedItem->catby) . "</recordOrigin>\r\n";
    $mods .= "<recordCreationDate>" . htmlspecialchars($exportedItem->catdate) . "</recordCreationDate>\r\n";
    $mods .= "<recordChangeDate>" . htmlspecialchars($exportedItem->updated) . "</recordChangeDate>\r\n";
    $mods .= "<recordChangeDate>" . htmlspecialchars($exportedItem->maintdate) . "</recordChangeDate>\r\n";
    $mods .= "</recordInfo>\r\n";
    $mods .= "<physicalDescription>\r\n";
    $mods .= "<extent>" . htmlspecialchars($exportedItem->printsize) . "</extent>\r\n";
    $mods .= "<extent>" . htmlspecialchars($exportedItem->filmsize) . "</extent>\r\n";
    $mods .= "<extent>" . htmlspecialchars($exportedItem->objname) . "</extent>\r\n";
    $mods .= "<extent>" . htmlspecialchars($exportedItem->origcopy) . "</extent>\r\n";
    $mods .= "<extent type='medium'>" . htmlspecialchars($exportedItem->medium) . "</extent>\r\n";
    $mods .= "<note type='condition'>" . htmlspecialchars($exportedItem->dimnotes) . "</note>\r\n";
    $mods .= "</physicalDescription>\r\n";
    $mods .= "<physicalLocation>" . htmlspecialchars($exportedItem->homeloc) . "</physicalLocation>\r\n";
    $mods .= "<physicalLocation>" . htmlspecialchars($exportedItem->collection) . "</physicalLocation>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield1) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield2) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield3) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield4) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield5) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->locfield6) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->negloc) . "</shelfLocator>\r\n";
    $mods .= "<shelfLocator>" . htmlspecialchars($exportedItem->negno) . "</shelfLocator>\r\n";
    $mods .= "<accessCondition><marmot:typeOfStatement>local</marmot:typeOfStatement>\r\n";
    $mods .= "<marmot:rightsStatement>" . htmlspecialchars($exportedItem->copyright) . "</marmot:rightsStatement>\r\n";
    $mods .= "</accessCondition>\r\n";
    $mods .= "<accessCondition><marmot:typeOfStatement>local</marmot:typeOfStatement>\r\n";
    $mods .= "<marmot:rightsStatement>" . htmlspecialchars($exportedItem->legal) . "</marmot:rightsStatement>\r\n";
    $mods .= "</accessCondition>\r\n";
    $mods .= "<name>\r\n";
    $mods .= "<namePart>" . htmlspecialchars($exportedItem->provenance) . "</namePart>\r\n";
    $mods .= "<role><roleTerm>Donor</roleTerm></role>\r\n";
    $mods .= "</name>\r\n";
    $mods .= "<extension>\r\n";
    $mods .= "<marmot:marmotLocal>\r\n";
    $mods .= "<marmot:hasPublisher>\r\n";
    $mods .= "<marmot:entityPid></marmot:entityPid>\r\n";
    $mods .= "<marmot:entityTitle>" . htmlspecialchars($exportedItem->studio) . "</marmot:entityTitle>\r\n";
    $mods .= "</marmot:hasPublisher>\r\n";
    $people = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->people);
    foreach ($people as $person) {
        $person = trim($person);
        if (strlen($person) > 0) {
            $mods .= "<marmot:relatedEntity type='person'>\r\n";
            $personPID = doesEntityExist($person);
            $mods .= "<marmot:entityPid>{$personPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($person) . "</marmot:entityTitle>\r\n";
            $mods .= "<marmot:entityRelationshipNote/>\r\n";
            $mods .= "</marmot:relatedEntity>\r\n";
        }
    }
    $places = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->place);
    foreach ($places as $place) {
        $place = trim($place);
        if (strlen($place) > 0) {
            $mods .= "<marmot:relatedEntity type='place'>\r\n";
            $placePID = doesEntityExist($place);
            $mods .= "<marmot:entityPid>{$placePID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($place) . "</marmot:entityTitle>\r\n";
            $mods .= "<marmot:entityRelationshipNote/>\r\n";
            $mods .= "</marmot:relatedEntity>\r\n";
        }
    }
    $events = preg_split('/\\r\\n|\\r|\\n/', $exportedItem->event);
    foreach ($events as $event) {
        $event = trim($event);
        if (strlen($event) > 0) {
            $mods .= "<marmot:relatedEntity type='event'>\r\n";
            $eventPID = doesEntityExist($event);
            $mods .= "<marmot:entityPid>{$eventPID}</marmot:entityPid>\r\n";
            $mods .= "<marmot:entityTitle>" . htmlspecialchars($event) . "</marmot:entityTitle>\r\n";
            $mods .= "<marmot:entityRelationshipNote/>\r\n";
            $mods .= "</marmot:relatedEntity>\r\n";
        }
    }
    $mods .= "</marmot:marmotLocal>\r\n";
    $mods .= "<marmot:contextNotes>" . htmlspecialchars($exportedItem->notes) . "</marmot:contextNotes>\r\n";
    $mods .= "<marmot:relationshipNotes>" . htmlspecialchars($exportedItem->relnotes) . "</marmot:relationshipNotes>\r\n";
    $mods .= "<marmot:migratedFileName>" . htmlspecialchars($exportedItem->imagefile) . "</marmot:migratedFileName>\r\n";
    $mods .= "</extension>\r\n";
    $mods .= "</mods>";
    return $mods;
}
function createOrganization($repository, $organization)
{
    $existingPID = doesEntityExist($organization);
    if ($existingPID) {
        return $existingPID;
    } else {
        //Create an entity within Islandora
        $entity = $repository->constructObject('organization');
        $entity->models = array('islandora:organizationCModel');
        $entity->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'marmot:organizations');
        $entity->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:entity_collection');
        $entity->label = $organization;
        $modsDatastream = $entity->constructDatastream('MODS');
        $modsDatastream->label = 'MODS Record';
        $modsDatastream->mimetype = 'text/xml';
        $modsDatastream->setContentFromString("<?xml version=\"1.0\"?><mods xmlns=\"http://www.loc.gov/mods/v3\" xmlns:marmot=\"http://marmot.org/local_mods_extension\" xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><mods:titleInfo><mods:title>{$organization}</mods:title></mods:titleInfo><mods:extension><marmot:marmotLocal><marmot:pikaOptions><marmot:includeInPika>yes</marmot:includeInPika><marmot:showInSearchResults>yes</marmot:showInSearchResults></marmot:pikaOptions></marmot:marmotLocal></mods:extension></mods>");
        $entity->ingestDatastream($modsDatastream);
        $repository->ingestObject($entity);
        $existingEntities[$organization] = $entity->id;
        return $entity->id;
    }
}
 //Get the name node for relative positioning
 $nameNode = $modsNode->getElementsByTagName('name')->item(0);
 if (strlen($copyRightStatement) > 0) {
     $copyrightHolderName = '';
     if (stripos($copyRightStatement, 'Eagle County Historical Society') !== false) {
         $copyrightHolderName = 'Eagle County Historical Society';
     } else {
         echo "Unknown copyright holder: {$copyRightStatement} \r\n<br/>";
         fwrite($logFile, "Unknown copyright holder: {$copyRightStatement} \r\n");
     }
     $accessCondition = $MODSxml->createElement('accessCondition');
     $accessCondition->appendChild($MODSxml->createElementNS('http://marmot.org/local_mods_extension', 'typeOfStatement', 'local'));
     $accessCondition->appendChild($MODSxml->createElementNS('http://marmot.org/local_mods_extension', 'rightsStatement', $copyRightStatement));
     if ($copyrightHolderName) {
         $rightsHolderElement = $MODSxml->createElementNS('http://marmot.org/local_mods_extension', 'rightsHolder');
         $rightsHolderPid = doesEntityExist($copyrightHolderName);
         if (!$rightsHolderPid) {
             $rightsHolderPid = createOrganization($repository, $copyrightHolderName);
         }
         $rightsHolderElement->appendChild($MODSxml->createElementNS('http://marmot.org/local_mods_extension', 'entityPid', $rightsHolderPid));
         $rightsHolderElement->appendChild($MODSxml->createElementNS('http://marmot.org/local_mods_extension', 'entityTitle', $copyrightHolderName));
         $accessCondition->appendChild($rightsHolderElement);
     }
     $modsNode->insertBefore($accessCondition, $nameNode);
 }
 $provenance = (string) $exportedItem->provenance;
 if (strlen($provenance) > 0) {
     $noteNode = $MODSxml->createElement('notes', str_replace('&', '&amp;', $provenance));
     if ($nameNode != null) {
         $modsNode->replaceChild($noteNode, $nameNode);
     } else {