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;
}
include_once dirname(__FILE__) . '/../domain/Person.php';
include_once dirname(__FILE__) . '/../domain/Shift.php';
include_once dirname(__FILE__) . '/../reportsAjax.php';
define("personID", "John7188475582");
//Manipulate these to
define("shiftID", "09-18-14-10-13");
//Search, add, or remove
define("projectID", "10-31-14-10-16");
define("NameFirst", "John");
//A person, project, or shift from the
define("NameLast", "Smith");
//Table; First check to see if
//John Smith is already in the table - GIOVI
echo 'testing reportsAjax.php</br>';
error_log('testing reportsAjax.php</br>');
createPerson();
createShift();
createProject();
addPersontoShift();
addPersontoProject();
getReport();
deletePerson();
deleteShift();
deleteProject();
echo 'reportsAjax.php testing complete</br>';
error_log('testing reportsAjax.php</br>');
function createPerson()
{
    $m = new Person("John", "Smith", "10-12-87", "Male", "555 Main Street", "Flushing", "NY", "11111", "7188475582", "2072654046", "*****@*****.**", "volunteer", " ", "Schedule", "I like helping out", "55555", "03-14-14", "email");
    $result = add_person($m);
    echo 'result is ' . $result . '</br>';