@ -2,42 +2,61 @@
// $Id$
// $Id$
/**
* @file
* ModsFormBuilder class
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/**
* ModsFormBuilder class ???
*/
class ModsFormBuilder extends FormBuilder {
class ModsFormBuilder extends FormBuilder {
static $MODS_NS = 'http://www.loc.gov/mods/v3';
static $MODS_NS = 'http://www.loc.gov/mods/v3';
protected $cm;
protected $cm;
protected $item;
protected $item;
protected $pid;
protected $pid;
function __construct($pid=null)
/**
{
* Constructor
* @param type $pid
*/
function __construct($pid=null) {
parent::__construct();
parent::__construct();
if ($pid !== null)
if ($pid !== null) {
{
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$this->pid=$pid;
$this->pid = $pid;
$this->cm = ContentModel::loadFromObject($pid);
$this->cm = ContentModel::loadFromObject($pid);
$this->item = new fedora_item($pid);
$this->item = new fedora_item($pid);
}
}
}
}
function handleEditMetadataForm(& $form_id, & $form_values, & $soap_client)
/**
{
* Handle Edit Metadata Form ???
* @param & $form_id
* @param & $form_values
* @param & $soap_client
*/
function handleEditMetadataForm(& $form_id, & $form_values, & $soap_client) {
$dom = new DomDocument("1.0", "UTF-8");
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
$dom->formatOutput = TRUE;
$mods = $this->modsFromForm($form_values,$dom);
$mods = $this->modsFromForm($form_values, $dom);
$dom->appendChild($mods);
$dom->appendChild($mods);
if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) {
if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) {
drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid'=>$this->pid)));
drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid' => $this->pid)));
}
}
drupal_goto('/fedora/repository/'.$this->pid);
drupal_goto('/fedora/repository/' . $this->pid);
}
}
function buildEditMetadataForm()
/**
{
* Build Edit Metadata Form
* @return array
*/
function buildEditMetadataForm() {
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
$form['indicator2'] = array(
$form['indicator2'] = array(
'#type' => 'fieldset',
'#type' => 'fieldset',
@ -45,7 +64,7 @@ class ModsFormBuilder extends FormBuilder {
);
);
if ($this->cm !== FALSE & & $this->item != NULL) {
if ($this->cm !== FALSE & & $this->item != NULL) {
$form['pid'] = array('#type'=>'hidden','#value'=>$this->pid);
$form['pid'] = array('#type' => 'hidden', '#value' => $this->pid);
$elements = $this->cm->getIngestFormElements();
$elements = $this->cm->getIngestFormElements();
$content = $this->item->get_datastream_dissemination('MODS');
$content = $this->item->get_datastream_dissemination('MODS');
@ -78,11 +97,11 @@ class ModsFormBuilder extends FormBuilder {
foreach ($element['parameters'] as $key => $val) {
foreach ($element['parameters'] as $key => $val) {
switch ($key) {
switch ($key) {
case '#autocomplete_path':
case '#autocomplete_path':
$val .= '/' . $form_values['storage']['collection_pid'];
$val .= '/' . $form_values['storage']['collection_pid'];
break;
break;
case '#exclude_from_edit_metadata':
case '#exclude_from_edit_metadata':
$includeEl= FALSE;
$includeEl = FALSE;
break;
break;
@ -92,25 +111,24 @@ class ModsFormBuilder extends FormBuilder {
// echo $nodeList->item(0)->nodeValue.' ';
// echo $nodeList->item(0)->nodeValue.' ';
// echo '< br / > ';
// echo '< br / > ';
if (is_string($nodeList))
if (is_string($nodeList)) {
{
$el['#default_value'] = $nodeList;
$el['#default_value']=$nodeList;
}
} else if ($nodeList->length > 1)
else if ($nodeList->length > 1) {
{
$el['#default_value'] = array();
$el['#default_value'] = array();
foreach ($nodeList as $node)
foreach ($nodeList as $node) {
{
$el['#default_value'][] = $node->nodeValue;
$el['#default_value'][] = $node->nodeValue;
}
}
} else if ($nodeList->length > 0)
}
{
else if ($nodeList->length > 0) {
if ($el['#type'] == 'list') {
if ($el['#type'] == 'list') {
$values= array();
$values = array();
for ($i=0;$i< $nodeList->length;$i++) {
for ($i = 0; $i < $nodeList->length; $i++) {
$values[]= $nodeList->item($i)->nodeValue;
$values[] = $nodeList->item($i)->nodeValue;
}
}
$el['#default_value']=join('; ',$values);
$el['#default_value'] = join('; ', $values);
} else {
}
else {
$el['#default_value'] = $nodeList->item(0)->nodeValue;
$el['#default_value'] = $nodeList->item(0)->nodeValue;
}
}
}
}
@ -118,52 +136,53 @@ class ModsFormBuilder extends FormBuilder {
}
}
if ($key != '#sticky') {
if ($key != '#sticky') {
$el[$key]= $val;
$el[$key] = $val;
}
}
}
}
if ($element['type'] == 'people')
if ($element['type'] == 'people') {
{
$names = $xpath->evaluate('/mods:mods/mods:name');
$names = $xpath->evaluate('/mods:mods/mods:name');
$people= array();
$people = array();
foreach ($names as $mname) {
foreach ($names as $mname) {
$type = $mname->getAttribute('type');
$type = $mname->getAttribute('type');
$role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue;
$role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue;
$nameParts = $mname->getElementsByTagName('namePart');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart)
foreach ($nameParts as $namePart) {
{
switch ($namePart->getAttribute('type')) {
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue; break;
case 'given': $given = $namePart->nodeValue;
case 'family': $family = $namePart->nodeValue; break;
break;
case 'termsOfAddress': $title = $namePart->nodeValue; break;
case 'family': $family = $namePart->nodeValue;
case 'date': $date = $namePart->nodeValue; break;
break;
default: $name = $namePart->nodeValue; break;
case 'termsOfAddress': $title = $namePart->nodeValue;
break;
case 'date': $date = $namePart->nodeValue;
break;
default: $name = $namePart->nodeValue;
break;
}
}
}
}
$person=array('role'=>$role);
$person = array('role' => $role);
switch ($type)
switch ($type) {
{
case 'personal':
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '. $family;
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
}
$person['name']= $name;
$person['name'] = $name;
$person['date']= $date;
$person['date'] = $date;
break;
break;
case 'organization':
case 'organization':
$person['organization'] = $name;
$person['organization'] = $name;
break;
break;
case 'conference':
case 'conference':
$person['conference']= $name;
$person['conference'] = $name;
$person['date']= $date;
$person['date'] = $date;
break;
break;
}
}
$people[]= $person;
$people[] = $person;
}
}
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
@ -172,45 +191,47 @@ class ModsFormBuilder extends FormBuilder {
$type = $mname->getAttribute('type');
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart)
foreach ($nameParts as $namePart) {
{
switch ($namePart->getAttribute('type')) {
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue; break;
case 'given': $given = $namePart->nodeValue;
case 'family': $family = $namePart->nodeValue; break;
break;
case 'termsOfAddress': $title = $namePart->nodeValue; break;
case 'family': $family = $namePart->nodeValue;
case 'date': $date = $namePart->nodeValue; break;
break;
default: $name = $namePart->nodeValue; break;
case 'termsOfAddress': $title = $namePart->nodeValue;
break;
case 'date': $date = $namePart->nodeValue;
break;
default: $name = $namePart->nodeValue;
break;
}
}
}
}
$person=array('subject'=>1);
$person = array('subject' => 1);
switch ($type)
switch ($type) {
{
case 'personal':
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '. $family;
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
}
$person['name']= $name;
$person['name'] = $name;
$person['date']= $date;
$person['date'] = $date;
break;
break;
case 'organization':
case 'organization':
$person['organization'] = $name;
$person['organization'] = $name;
break;
break;
case 'conference':
case 'conference':
$person['conference']= $name;
$person['conference'] = $name;
$person['date']= $date;
$person['date'] = $date;
break;
break;
}
}
$people[]= $person;
$people[] = $person;
}
}
$el['#default_value'] = $people;
$el['#default_value'] = $people;
}
}
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options']= isset($element['authoritative_list'])?$element['authoritative_list']: array();
$el['#options'] = isset($element['authoritative_list']) ? $element['authoritative_list'] : array();
}
}
if ($includeEl) {
if ($includeEl) {
@ -225,21 +246,24 @@ class ModsFormBuilder extends FormBuilder {
);
);
return $form;
return $form;
}
}
}
}
}
}
function handleModsForm(& $form_values,& $form_state) {
/**
* Handle Mods Form
* @param & $form_values
* @param & $form_state
*/
function handleModsForm(& $form_values, & $form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$form_state['storage']['people']=NULL; //clears out old entities for the next run of the formbuilder.
$form_state['storage']['people'] = NULL; //clears out old entities for the next run of the formbuilder.
$dom = new DomDocument("1.0", "UTF-8");
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
$dom->formatOutput = TRUE;
$pid=$form_values['pid'];
$pid = $form_values['pid'];
$rootElement = $dom->createElement("foxml:digitalObject");
$rootElement = $dom->createElement("foxml:digitalObject");
$rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('PID', "$pid");
$rootElement->setAttribute('PID', "$pid");
@ -257,9 +281,9 @@ class ModsFormBuilder extends FormBuilder {
$collectionPid = $form_values['collection_pid'];
$collectionPid = $form_values['collection_pid'];
if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) {
if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) {
$collectionName =trim($cp->getName());
$collectionName = trim($cp->getName());
if (trim($collectionName)!='') {
if (trim($collectionName) != '') {
$form_values['dc_relation']=$collectionName;
$form_values['dc_relation'] = $collectionName;
}
}
}
}
// Create MODS
// Create MODS
@ -280,26 +304,30 @@ class ModsFormBuilder extends FormBuilder {
//for some reason, ingest_from_FOXML does not generate a JMS message
//for some reason, ingest_from_FOXML does not generate a JMS message
//I just modify the workflow DS and it sends a JMS message.
//I just modify the workflow DS and it sends a JMS message.
$item = new Fedora_Item($object->pid);
$item = new Fedora_Item($object->pid);
$item->modify_datastream_by_value( $item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml');
$item->modify_datastream_by_value($item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml');
if (!empty($object->pid)) {
if (!empty($object->pid)) {
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/'. $object->pid))), "status");
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/' . $object->pid))), "status");
}
}
if (!empty( $_SESSION['fedora_ingest_files'])) {
if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
file_delete($createdFile);
file_delete($createdFile);
}
}
}
}
file_delete($form_values['ingest-file-location']);
file_delete($form_values['ingest-file-location']);
}
} catch (exception $e) {
catch (exception $e) {
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
return;
return;
}
}
}
}
/**
* Create Collection Policy ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createCollectionPolicy($form_values, & $dom, & $rootElement) {
function createCollectionPolicy($form_values, & $dom, & $rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']);
$model = new fedora_item($form_values['content_model_pid']);
@ -308,8 +336,8 @@ class ModsFormBuilder extends FormBuilder {
$cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL');
$cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL');
$cpDom = DOMDocument::loadXML($cp);
$cpDom = DOMDocument::loadXML($cp);
$cpRootEl = $cpDom->getElementsByTagName('collection_policy');
$cpRootEl = $cpDom->getElementsByTagName('collection_policy');
if ($cpRootEl->length >0) {
if ($cpRootEl->length > 0) {
$cpRootEl=$cpRootEl->item(0);
$cpRootEl = $cpRootEl->item(0);
$newNode = $dom->importNode($cpRootEl, TRUE);
$newNode = $dom->importNode($cpRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -329,6 +357,12 @@ class ModsFormBuilder extends FormBuilder {
}
}
}
}
/**
* Create Workflow Stream ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createWorkflowStream($form_values, & $dom, & $rootElement) {
function createWorkflowStream($form_values, & $dom, & $rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']);
$model = new fedora_item($form_values['content_model_pid']);
@ -337,8 +371,8 @@ class ModsFormBuilder extends FormBuilder {
$workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL');
$workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL');
$workflowDom = DOMDocument::loadXML($workflow);
$workflowDom = DOMDocument::loadXML($workflow);
$workflowRootEl = $workflowDom->getElementsByTagName('workflow');
$workflowRootEl = $workflowDom->getElementsByTagName('workflow');
if ($workflowRootEl->length >0) {
if ($workflowRootEl->length > 0) {
$workflowRootEl=$workflowRootEl->item(0);
$workflowRootEl = $workflowRootEl->item(0);
$newNode = $dom->importNode($workflowRootEl, TRUE);
$newNode = $dom->importNode($workflowRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -358,6 +392,12 @@ class ModsFormBuilder extends FormBuilder {
}
}
}
}
/**
* Create mods Stream ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createModsStream($form_values, & $dom, & $rootElement) {
function createModsStream($form_values, & $dom, & $rootElement) {
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -372,15 +412,19 @@ class ModsFormBuilder extends FormBuilder {
$content = $dom->createElement("foxml:xmlContent");
$content = $dom->createElement("foxml:xmlContent");
$version->appendChild($content);
$version->appendChild($content);
$mods = $this->modsFromForm($form_values,$dom);
$mods = $this->modsFromForm($form_values, $dom);
$content->appendChild($mods);
$content->appendChild($mods);
$rootElement->appendChild($datastream);
$rootElement->appendChild($datastream);
}
}
/**
function modsFromForm(& $form_values,& $dom)
* Mods From From ?????
{
* @param type $form_values
* @param type $dom
* @return type
*/
function modsFromForm(& $form_values, & $dom) {
///begin writing MODS
///begin writing MODS
$mods = $dom->createElement("mods:mods");
$mods = $dom->createElement("mods:mods");
@ -399,11 +443,11 @@ class ModsFormBuilder extends FormBuilder {
}
}
if (isset($form_values['mods_alternative_titles']) & & trim($form_values['mods_alternative_titles']) != '') {
if (isset($form_values['mods_alternative_titles']) & & trim($form_values['mods_alternative_titles']) != '') {
$titles=preg_split('/\s+\;\s+/',trim($form_values['mods_alternative_titles']));
$titles = preg_split('/\s+\;\s+/', trim($form_values['mods_alternative_titles']));
foreach ($titles as $t) {
foreach ($titles as $t) {
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ;
$titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',$t);
$title = $dom->createElement('mods:title', $t);
$titleinfo->appendChild($title);
$titleinfo->appendChild($title);
$mods->appendChild($titleinfo);
$mods->appendChild($titleinfo);
}
}
@ -411,8 +455,8 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_alternative_title']) & & trim($form_values['mods_alternative_title']) != '') {
if (isset($form_values['mods_alternative_title']) & & trim($form_values['mods_alternative_title']) != '') {
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ;
$titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',trim($form_values['mods_alternative_title']));
$title = $dom->createElement('mods:title', trim($form_values['mods_alternative_title']));
$titleinfo->appendChild($title);
$titleinfo->appendChild($title);
$mods->appendChild($titleinfo);
$mods->appendChild($titleinfo);
}
}
@ -423,7 +467,7 @@ class ModsFormBuilder extends FormBuilder {
}
}
if (isset($form_values['pid']) & & trim($form_values['pid']) != '') {
if (isset($form_values['pid']) & & trim($form_values['pid']) != '') {
$identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/','\/',$form_values['pid']))));
$identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/', '\/', $form_values['pid']))));
$identifier->setAttribute('type', 'hdl');
$identifier->setAttribute('type', 'hdl');
$mods->appendChild($identifier);
$mods->appendChild($identifier);
}
}
@ -457,7 +501,7 @@ class ModsFormBuilder extends FormBuilder {
$addOriginInfo = FALSE;
$addOriginInfo = FALSE;
if (isset($form_values['mods_pubinfo_place']) & & trim($form_values['mods_pubinfo_place']) != '') {
if (isset($form_values['mods_pubinfo_place']) & & trim($form_values['mods_pubinfo_place']) != '') {
$place = $dom->createElement('mods:place');
$place = $dom->createElement('mods:place');
$placeTerm=$dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place'])));
$placeTerm = $dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place'])));
$placeTerm->setAttribute('type', 'text');
$placeTerm->setAttribute('type', 'text');
$place->appendChild($placeTerm);
$place->appendChild($placeTerm);
$originInfo->appendChild($place);
$originInfo->appendChild($place);
@ -480,51 +524,51 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_pubinfo_date']) & & trim($form_values['mods_pubinfo_date']) != '' & &
if (isset($form_values['mods_pubinfo_date']) & & trim($form_values['mods_pubinfo_date']) != '' & &
isset($form_values['mods_pubinfo_dateType']) & & trim($form_values['mods_pubinfo_dateType']) != '') {
isset($form_values['mods_pubinfo_dateType']) & & trim($form_values['mods_pubinfo_dateType']) != '') {
if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) {
if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) {
$date = $dom->createElement('mods:'. trim($form_values['mods_pubinfo_dateType']) .'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date = $dom->createElement('mods:' . trim($form_values['mods_pubinfo_dateType']) . 'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
}
}
else {
else {
//how to handle other types? otherDate?
//how to handle other types? otherDate?
$date= $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date = $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType'])));
$date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType'])));
}
}
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
} else {
}
else {
if (isset($form_values['mods_createdDate'])) {
if (isset($form_values['mods_createdDate'])) {
$date = $dom->createElement('mods:createdDate',htmlspecialchars(trim($form_values['mods_createdDate'])));
$date = $dom->createElement('mods:createdDate', htmlspecialchars(trim($form_values['mods_createdDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_issuedDate'])) {
if (isset($form_values['mods_issuedDate'])) {
$date = $dom->createElement('mods:issuedDate',htmlspecialchars(trim($form_values['mods_issuedDate'])));
$date = $dom->createElement('mods:issuedDate', htmlspecialchars(trim($form_values['mods_issuedDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_copyrightDate'])) {
if (isset($form_values['mods_copyrightDate'])) {
$date = $dom->createElement('mods:copyrightDate',htmlspecialchars(trim($form_values['mods_copyrightDate'])));
$date = $dom->createElement('mods:copyrightDate', htmlspecialchars(trim($form_values['mods_copyrightDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_capturedDate'])) {
if (isset($form_values['mods_capturedDate'])) {
$date = $dom->createElement('mods:capturedDate',htmlspecialchars(trim($form_values['mods_capturedDate'])));
$date = $dom->createElement('mods:capturedDate', htmlspecialchars(trim($form_values['mods_capturedDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
}
}
if (isset($form_values['mods_pubinfo_journalFreq']) & & trim($form_values['mods_pubinfo_journalFreq']) != '') {
if (isset($form_values['mods_pubinfo_journalFreq']) & & trim($form_values['mods_pubinfo_journalFreq']) != '') {
$frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq'])));
$frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq'])));
$originInfo->appendChild($frequency);
$originInfo->appendChild($frequency);
$issuance= $dom->createElement('mods:issuance', 'journal');
$issuance = $dom->createElement('mods:issuance', 'journal');
$originInfo->appendChild($issuance);
$originInfo->appendChild($issuance);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
elseif (isset($form_values['mods_pubinfo_journalFreq'])) {
elseif (isset($form_values['mods_pubinfo_journalFreq'])) {
$issuance= $dom->createElement('mods:issuance', 'monographic');
$issuance = $dom->createElement('mods:issuance', 'monographic');
$originInfo->appendChild($issuance);
$originInfo->appendChild($issuance);
}
}
@ -540,7 +584,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_caption']) & & trim($form_values['mods_caption']) != '') {
if (isset($form_values['mods_caption']) & & trim($form_values['mods_caption']) != '') {
$note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption'])));
$note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption'])));
$note->setAttribute('type','caption');
$note->setAttribute('type', 'caption');
$mods->appendChild($note);
$mods->appendChild($note);
}
}
@ -550,14 +594,12 @@ class ModsFormBuilder extends FormBuilder {
}
}
if (isset($form_values['mods_language']) & & trim($form_values['mods_language']) != '')
if (isset($form_values['mods_language']) & & trim($form_values['mods_language']) != '') {
{
$languageList = explode(';', htmlspecialchars($form_values['mods_language']));
$languageList = explode(';', htmlspecialchars($form_values['mods_language']));
foreach ($languageList as $lang)
foreach ($languageList as $lang) {
{
$language = $dom->createElement('mods:language');
$language = $dom->createElement('mods:language');
$langTerm = $dom->createElement('mods:languageTerm',htmlspecialchars($lang));
$langTerm = $dom->createElement('mods:languageTerm', htmlspecialchars($lang));
$langTerm->setAttribute('type', 'text');
$langTerm->setAttribute('type', 'text');
$language->appendChild($langTerm);
$language->appendChild($langTerm);
$mods->appendChild($language);
$mods->appendChild($language);
}
}
@ -573,7 +615,7 @@ class ModsFormBuilder extends FormBuilder {
$hasSubject = TRUE;
$hasSubject = TRUE;
$geographic = $dom->createElement('mods:hierarchicalGeographic');
$geographic = $dom->createElement('mods:hierarchicalGeographic');
$country=$dom->createElement('mods:country', htmlspecialchars($form_values['mods_country']));
$country = $dom->createElement('mods:country', htmlspecialchars($form_values['mods_country']));
$geographic->appendChild($country);
$geographic->appendChild($country);
if (isset($form_values['mods_province']) & & trim($form_values['mods_province']) != '') {
if (isset($form_values['mods_province']) & & trim($form_values['mods_province']) != '') {
@ -608,7 +650,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_subjtitle']) & & trim($form_values['mods_subjtitle']) != '') {
if (isset($form_values['mods_subjtitle']) & & trim($form_values['mods_subjtitle']) != '') {
$hasSubject = TRUE;
$hasSubject = TRUE;
$titleInfo= $dom->createElement('mods:titleInfo');
$titleInfo = $dom->createElement('mods:titleInfo');
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle']));
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle']));
$titleInfo->appendChild($title);
$titleInfo->appendChild($title);
$subject->appendChild($titleInfo);
$subject->appendChild($titleInfo);
@ -637,19 +679,18 @@ class ModsFormBuilder extends FormBuilder {
$modifications = trim($form_values['mods_cc']['cc']['cc_modifications']);
$modifications = trim($form_values['mods_cc']['cc']['cc_modifications']);
$jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']);
$jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']);
module_load_include('inc','islandora_form_elements','includes/creative_commons.inc');
// Include islandora form elements only if needed ??
module_load_include('inc', 'islandora_form_elements', 'includes/creative_commons.inc');
if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction]))
if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction]))
$jurisdiction= '';
$jurisdiction = '';
$version = CreativeCommons::$cc_versions[$jurisdiction];
$version = CreativeCommons::$cc_versions[$jurisdiction];
$license = 'by'. ($commercial != ''?'-'.$commercial:'') . ($modifications != ''?'-'.$modifications:'') . '/' . $version . '/'.($jurisdiction != ''?$jurisdiction.'/':'') ;
$license = 'by' . ($commercial != '' ? '-' . $commercial : '') . ($modifications != '' ? '-' . $modifications : '') . '/' . $version . '/' . ($jurisdiction != '' ? $jurisdiction . '/' : '');
$accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license));
$accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license));
$accessCondition->setAttribute('type', 'Creative Commons License');
$accessCondition->setAttribute('type', 'Creative Commons License');
$mods->appendChild($accessCondition);
$mods->appendChild($accessCondition);
}
}
if (isset($form_values['mods_rights']) & & trim($form_values['mods_rights']) != '') {
if (isset($form_values['mods_rights']) & & trim($form_values['mods_rights']) != '') {
@ -658,10 +699,10 @@ class ModsFormBuilder extends FormBuilder {
$mods->appendChild($accessCondition);
$mods->appendChild($accessCondition);
}
}
if (isset($form_values['mods_people']) & & isset($form_values['mods_people']['people']) & & is_array($form_values['mods_people']['people']) ) {
if (isset($form_values['mods_people']) & & isset($form_values['mods_people']['people']) & & is_array($form_values['mods_people']['people'])) {
foreach ($form_values['mods_people']['people'] as $key => $val) {
foreach ($form_values['mods_people']['people'] as $key => $val) {
$name = $dom->createElement('mods:name');
$name = $dom->createElement('mods:name');
$appendName=FALSE;
$appendName = FALSE;
if (isset($val['role'])) {
if (isset($val['role'])) {
$role = $dom->createElement('mods:role');
$role = $dom->createElement('mods:role');
$roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role'])));
$roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role'])));
@ -674,43 +715,43 @@ class ModsFormBuilder extends FormBuilder {
if (isset($val['organization'])) {
if (isset($val['organization'])) {
$name->setAttribute('type', 'organization');
$name->setAttribute('type', 'organization');
if (trim($val['organization']) != '') {
if (trim($val['organization']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
elseif (isset($val['conference'])) {
elseif (isset($val['conference'])) {
$name->setAttribute('type', 'conference');
$name->setAttribute('type', 'conference');
if (trim($val['conference']) != '') {
if (trim($val['conference']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
else {
else {
$name->setAttribute('type', 'personal');
$name->setAttribute('type', 'personal');
if (trim($val['name']) != '') {
if (trim($val['name']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['name'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['name'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
if (isset($val['date'])) {
if (isset($val['date'])) {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['date'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['date'])));
$namePart->setAttribute('type','date');
$namePart->setAttribute('type', 'date');
$name->appendChild($namePart);
$name->appendChild($namePart);
}
}
if ($appendName) {
if ($appendName) {
if (isset($val['subject'])) {
if (isset($val['subject'])) {
$subject->appendChild($name);
$subject->appendChild($name);
$hasSubject=TRUE;
$hasSubject = TRUE;
} else {
}
else {
$mods->appendChild($name);
$mods->appendChild($name);
}
}
}
}
}
}
}
}