forked from Islandora/islandora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formClass.inc
857 lines (760 loc) · 33.1 KB
/
formClass.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
<?php
// $Id$
/*
* Created on Jan 22, 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class formClass {
function formClass() {
module_load_include('inc', 'formClass', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
/*
* create the paths for urls and map them to php functions
*/
function createMenu() {
$items = array();
$items['admin/settings/fedora_repository'] = array(
'title' => t('Fedora collection list'),
'description' => t('Enter the Fedora Collection information here'),
'page callback' => 'drupal_get_form',
'page arguments' => array('fedora_repository_admin'),
//'access' => user_access('access administration pages'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
// 'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/fedora_repository/collection'] = array(
'title' => t('Collection list'),
'description' => t('Enter the Fedora collection information here.'),
'access arguments' => array('administer site configuration'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/settings/fedora_repository/demoobjects'] = array(
'title' => t('Install demos'),
'description' => t('Install example content models and collections to get started using Islandora and Fedora.'),
'page callback' => 'fedora_repository_install_demos_page',
'access arguments' => array('add fedora datastreams'),
'type' => MENU_LOCAL_TASK,
);
$items['islandoracm.xsd'] = array(
'title' => t('Islandoracm XML Schema Definition'),
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('islandoracm.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['collection_policy.xsd'] = array(
'title' => t('Islandoracm XML Schema Definition'),
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('collection_policy.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['fedora'] = array(
// 'title' => t('Digital repository'),
'page callback' => 'repository_page',
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['fedora/repository'] = array(
// 'title' => t('Digital repository'),
'page callback' => 'repository_page',
'type' => MENU_NORMAL_ITEM,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['fedora/repository/service'] = array(
'page callback' => 'repository_service',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository/object_download'] = array(
'title' => t('Download object'),
'page callback' => 'fedora_object_as_attachment',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection')
);
$items['fedora/repository/editmetadata'] = array(
'title' => t('Edit metadata'),
'page callback' => 'fedora_repository_edit_qdc_page',
// 'page arguments' => array(1),
//'type' => MENU_LOCAL_TASK,
'type' => MENU_CALLBACK,
'access arguments' => array('edit fedora meta data')
);
$items['fedora/repository/purgeStream'] = array(
'title' => t('Purge data stream'),
'page callback' => 'fedora_repository_purge_stream',
'type' => MENU_CALLBACK,
'access arguments' => array('purge objects and datastreams')
);
$items['fedora/repository/replaceStream'] = array(
'title' => t('Replace Stream'),
'page callback' => 'fedora_repository_replace_stream',
// 'callback arguments' => array(3, 4),
'type' => MENU_CALLBACK,
// 'access callback' => 'fedora_repository_user_access',
'access arguments' => array('add fedora datastreams'),
);
$items['fedora/repository/purgeObject'] = array(
'title' => t('Purge object'),
'page callback' => 'fedora_repository_purge_object',
// 'type' => MENU_LOCAL_TASK,
'type' => MENU_CALLBACK,
'access arguments' => array('purge objects and datastreams')
);
$items['fedora/repository/addStream'] = array(
'title' => t('Add stream'),
'page callback' => 'add_stream',
// 'type' => MENU_LOCAL_TASK,
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams')
);
$items['fedora/repository/collection'] = array(
'title' => t('Collection view'),
'page callback' => 'fedora_collection_view',
'type' => MENU_CALLBACK,
'access argruments' => array('view fedora collection')
);
//new for mnpl******************************************
$items['fedora/repository/mnpl_advanced_search'] = array(
'title' => t('Repository advanced search'),
'page callback' => 'fedora_repository_mnpl_advanced_search',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection')
);
$items['fedora/ingestObject'] = array(
'title' => t('Ingest object'),
'page callback' => 'fedora_repository_ingest_object',
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams')
);
$items['fedora/repository/list_terms'] = array(
'title' => t('List terms'),
'page callback' => 'fedora_repository_list_terms',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection')
);
$items['fedora/tagging/add_tag/js'] = array(
'page callback' => 'fedora_tagging_add_tag_js',
'access arguments' => array('edit tags datastream'),
'type' => MENU_CALLBACK,
);
/* Export functionality */
$items['fedora/basket'] = array(
'title' => t('Fedora Basket'),
'description' => t('View and download objects added to your basket'),
'page callback' => 'fedora_repository_basket',
'access arguments' => array('view fedora collection'),
'type' => MENU_CALLBACK,
);
$items['fedora/repository/addToBasket'] = array(
'page callback' => 'fedora_repository_add_to_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository/removeFromBasket'] = array(
'page callback' => 'fedora_repository_remove_from_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository/add_search_results_to_basket'] = array(
'page callback' => 'fedora_repository_add_search_results_to_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
/*
$items['fedora/item'] = array (
'title' => t('Repository Item'),
'access arguments' => array('view fedora collection'),
'page callback' => 'fedora_repository_item',
'type' => MENU_NORMAL_ITEM,
);
$item['feodra/item/view'] = array (
'title' => t('View Repository Item'),
'access arguments' => array('view fedora collection'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
*/
// $items = array_merge($items,$irItems);
return $items;
}
function createAdminForm() {
if (!user_access('administer site configuration')) {
drupal_set_message(t('You must be a site administrator to edit the Fedora collecitons list.'), 'error');
return;
}
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$form = array();
$form['fedora_repository_name'] = array(
'#type' => 'textfield',
'#title' => t('Default collection name'),
'#default_value' => variable_get('fedora_repository_name', 'Islandora demos collection'),
'#description' => t('The Name of the collection to grab the list of items from'),
'#required' => TRUE,
'#weight' => -2
);
$form['fedora_repository_pid'] = array(
'#type' => 'textfield',
'#title' => t('Default collection PID'),
'#default_value' => variable_get('fedora_repository_pid', 'islandora:top'),
'#description' => t('The PID of the collection object to grab the list of items from'),
'#required' => TRUE,
'#weight' => -2
);
$form['fedora_collection_model_pid'] = array(
'#type' => 'textfield',
'#title' => t('Default Collection Model PID'),
'#default_value' => variable_get('fedora_collection_model_pid', 'islandora:collectionCModel'),
'#description' => t('The PID of the default Collection Model Object'),
'#required' => TRUE,
'#weight' => -2
);
$form['fedora_content_model_collection_pid'] = array(
'#type' => 'textfield',
'#title' => t('Default Content Model Collection PID'),
'#default_value' => variable_get('fedora_content_model_collection_pid', 'islandora:ContentModelCollection'),
'#description' => t('The PID of the Content Model Collection Object'),
'#required' => TRUE,
'#weight' => -2
);
$form['fedora_repository_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora RISearch URL'),
'#default_value' => variable_get('fedora_repository_url',
'http://localhost:8080/fedora/risearch'),
'#description' => t('The url of the Fedora server'), '#required' => TRUE,
'#weight' => 0
);
$form['fedora_fgsearch_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Lucene search URL'),
'#default_value' => variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'),
'#description' => t('The url of the Lucene Fedora server'),
'#required' => TRUE,
'#weight' => 0
);
$form['fedora_index_name'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Lucene index name'),
'#default_value' => variable_get('fedora_index_name', 'BasicIndex'),
'#description' => t('The name of the Lucene index to search'),
'#required' => TRUE,
'#weight' => 0
);
$form['fedora_soap_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP Url'),
'#default_value' => variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'),
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => 0,
// '#suffix' => '<p>'. (fedora_available() ? '<img src="'. url('misc/watchdog-ok.png') . '"/>'. t('Successfully connected to Fedora server at ') : '<img src="'. url('misc/watchdog-error.png') . '"/> '. t('Unable to connect to Fedora server at ')) . variable_get('fedora_soap_url', '') . '</p>',
'#suffix' => '<p>' . (fedora_available() ? '<img src="' . url('misc/watchdog-ok.png') . '"/>' . t('Successfully connected to Fedora server at !fedora_soap_url', array('!fedora_soap_url' => variable_get('fedora_soap_url', ''))) : '<img src="' . url('misc/watchdog-error.png') . '"/> ' . t('Unable to connect to Fedora server at !fedora_soap_url</p>', array('!fedora_soap_url' => variable_get('fedora_soap_url', '')))),
);
$form['fedora_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora base URL'),
'#default_value' => variable_get('fedora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST-type connections'),
'#required' => TRUE,
'#weight' => 0,
);
$form['fedora_soap_manage_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP management URL'),
'#default_value' => variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl'), '#description' => t('The URL to use for SOAP API-M connections'),
'#required' => TRUE,
'#weight' => 0
);
$form['fedora_solr_search_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Solr search URL'),
'#default_value' => variable_get('fedora_solr_search_url', 'http://localhost:8080/solr'), '#description' => t('The URL to use for Solr searching'),
'#required' => TRUE,
'#weight' => 0
);
/*
$form['fedora_default_display_pid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Object Pid' ),
'#default_value' => variable_get('fedora_default_display_pid', 'demo:10'),
'#description' => t('Object Pid of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
);
$form['fedora_default_display_dsid'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Default Display Datastream ID' ),
'#default_value' => variable_get('fedora_default_display_dsid', 'TN'),
'#description' => t('Object Datastream id of an Image to show if the requested pid/datastream cannot be found'),
'#required' => TRUE,
'#weight' => 0
);
*/
$form['fedora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '),
'#description' => t('The PID namespaces that you are allowed to see from this Drupal install. In reality this can be more than a namespace as it could include demo:mydemos etc. Can be a space seperated list to include more than one PID namespace.'),
'#required' => TRUE,
'#weight' => 0
);
/*
$form['fedora_admin_user'] = array(
'#type' => 'textfield',
'#title' => t('A user with the Drupal role administrator'),
'#default_value' => variable_get('fedora_admin_user', 'admin'),
'#description' => t('A user with the administrator role. This is the user the Islandora module will use when admin access is needed for a task, such as creating a collection object for a new user.'),
'#required' => TRUE, '#weight' => 0
);
$form['fedora_searchterms_location'] = array(
'#type' => 'file',
'#title' => 'SearchTerms.xml file location',
);
*/
$form['fedora_object_display_title'] = array(
'#type' => 'select',
'#title' => t('Display Object Title Behaviour'),
'#default_value'=> variable_get('fedora_object_display_title', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the object (or collection) title when viewing an object/collection page.'),
);
$form['fedora_object_display_description'] = array(
'#type' => 'select',
'#title' => t('Display Object Description Behaviour'),
'#default_value'=> variable_get('fedora_object_display_description', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the default object (or collection) description fieldset when viewing an object/collection page.'),
);
$form['fedora_collection_display_list'] = array(
'#type' => 'select',
'#title' => t('Display Collection List Behaviour'),
'#default_value'=> variable_get('fedora_collection_display_list', ObjectHelper::$DISPLAY_ALWAYS),
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS=>t('Always'),ObjectHelper::$DISPLAY_NEVER=>t('Never'),ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT=>t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the list of objects when viewing a collection page.'),
);
//Export functionality
$form['module']['export_area'] = array(
'#type' => 'textfield',
'#title' => t('Export area'),
'#default_value' => variable_get('export_area', file_directory_path() . '/fedora_export_area'),
'#description' => t("Path to the export area. It must be accessible by druapl (i.e. apache user)."),
'#required' => TRUE,
);
$form['#attributes'] = array('enctype' => "multipart/form-data");
// Additional form handling for file uploads.
$form['#submit'][] = 'fedora_repository_admin_settings_submit';
return system_settings_form($form);
}
function updateMetaData($form_id, $form_values, $client) {
// ======================================
// = begin creation of foxml dom object =
// ======================================
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
///begin writing qdc
$oai = $dom->createElement("oai_dc:dc");
$oai->setAttribute('xmlns:oai_dc', "http://www.openarchives.org/OAI/2.0/oai_dc/");
$oai->setAttribute('xmlns:dc', "http://purl.org/dc/elements/1.1/");
$oai->setAttribute('xmlns:dcterms', "http://purl.org/dc/terms/");
$oai->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
// DC elements
$previousElement = NULL; // Used in case we have to nest elements for qualified dublin core.
foreach ($form_values as $key => $value) {
$index = strrpos($key, '-');
$key = substr($key, 0, $index);
$test = substr($key, 0, 2);
if ($test == 'dc' || $test == 'ap') { // Don't try to process other form values.
try {
if (!strcmp(substr($key, 0, 4), 'app_')) {
$key = substr($key, 4);
$previousElement->appendChild($dom->createElement($key, $value));
}
else {
$previousElement = $dom->createElement($key, $value);
$oai->appendChild($previousElement);
}
} catch (exception $e) {
drupal_set_message(t($e->getMessage()), 'error');
continue;
}
}
}
$dom->appendChild($oai);
if (!$client) {
return;
}
$pid = $form_values['pid'];
$dsId = $form_values['dsid'];
$params = array(
"pid" => $pid,
"dsID" => $dsId,
"altIDs" => "",
"dsLabel" => "Qualified Dublin Core",
"MIMEType" => "text/xml",
"formatURI" => "URL",
"dsContent" => $dom->saveXML(), "checksumType" => "DISABLED", "checksum" => "none",
"logMessage" => "datastream_modified", "force" => "TRUE");
try {
$object = $client->__soapCall('ModifyDatastreamByValue', array($params));
} catch (exception $e) {
drupal_set_message(t("Error updating metadata ") . $e->getMessage(), 'error');
}
}
// queries the collection object for a childsecurity datastream and if found parses it
// to determine if this user is allowed to ingest in this collection
// we assume if they are able to modify objects in the collection they can ingest as well.
function can_ingest_here($collection_pid) {
module_load_include('inc', 'fedora_repository', 'SecurityClass');
$securityClass = new SecurityClass();
return $securityClass->canIngestHere($collection_pid);
}
/**
* Create a multi step form (wizard) for ingesting objects into Fedora
*/
function createIngestForm($collection_pid, $collection_label, &$form_state) {
global $user;
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
// drupal_add_js("function _imce_ingest_ImceFinish(path, w, h, s, imceWin) {imceWin.close(); document.getElementById('edit-ingest-file-location').value = path;}",'inline','header');
if (!user_access('ingest new fedora objects')) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return '';
}
if (empty($form_state['storage']['step'])) {
// we are coming in without a step, so default to step 1
$form_state['storage']['step'] = 1;
}
//this uses drupal's permissions at this point no xacml yet. xacml decisions are made by fedora
if (!$this->can_ingest_here($collection_pid)) {
drupal_set_message(t('You do not have premission to ingest here.'));
return '';
}
if ($collection_pid == NULL) {
drupal_set_message(t('You must specify an collection object pid to ingest an object.'), 'error');
return FALSE;
}
if (($cp = CollectionPolicy::loadFromCollection($collection_pid)) === FALSE) {
drupal_set_message(t('Unable to load collection policy \'' . $collection_pid . '\'.'));
return FALSE;
}
$contentModels = $cp->getContentModels();
if (!$contentModels) {
drupal_set_message(t('No content models associated with this collection: !collection_label. Please contact your administrator.', array('!collection_label' => $collection_label)), 'error');
return FALSE;
}
$modelsForForm = array();
foreach ($contentModels as $contentModel) {
$identifier = $contentModel->getIdentifier();
$name = $contentModel->name;
$modelsForForm["$identifier"] = "$name";
}
switch ($form_state['storage']['step']) {
case 1:
$form['indicator'] = array(
'#type' => 'fieldset',
'#title' => t('Ingest digital object into collection_pid !collection_label Step #1', array('collection_pid' => $collection_pid, '!collection_label' => $collection_label))
);
$form['indicator']['models'] = array(// content models available
'#type' => 'select',
'#title' => t('Content models available'),
'#options' => $modelsForForm,
//'#description' => t('Content models available in this collection. A content model defines what is allowed in a collection and what to do with a file when it is uploaded (An example may creating a thumbnail from an image.).')
'#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> ')
);
break;
case 2:
module_load_include('inc', 'fedora_repository', 'MimeClass'); // Why this include? --Zac, 2010-09-17
$contentModelPid = ContentModel::getPidFromIdentifier($form_state['values']['models']);
$contentModelDsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']);
if (($cm = ContentModel::loadFromModel($contentModelPid, $contentModelDsid)) !== FALSE) {
$form = $cm->buildIngestForm($form, $form_state);
if ($form === FALSE) {
drupal_set_message(t("Error Building Ingest Form."), 'error');
foreach (ContentModel::$errors as $err) {
drupal_set_message($err, 'error');
}
}
}
break;
}
$form['collection_pid'] = array(
'#type' => 'hidden',
'#value' => $collection_pid
);
if ($form_state['storage']['step'] < 2) {
$button_name = t('Next');
}
else {
$prefix = t('Please be patient. Once you click next there may be a number of files created. Depending on your content model this could take a few minutes to process.<br />');
$button_name = t('Ingest');
}
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_ingest_form_submit'),
'#value' => $button_name
);
return $form;
}
// this function may not be being used
function createAddDataStreamForm($pid, &$form_state) {
//dump_vars($form_state);
// Populate the list of datastream IDs.
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$obj_helper = new ObjectHelper();
$content_models = $obj_helper->get_content_models_list($pid);
$available_dsids = array();
if (!empty($content_models)) {
foreach ($content_models as $content_model) {
if (($cm = ContentModel::loadFromModel($content_model)) !== FALSE) {
$newElements = $cm->listDatastreams();
if (!empty($newElements)) {
$available_dsids = array_merge($available_dsids, $newElements);
}
}
}
}
$item = new Fedora_Item($pid);
$used_datastreams = $item->get_datastreams_list_as_SimpleXML();
$used_datastream_ids = array();
foreach ($used_datastreams->datastreamDef as $used_datastream) {
array_push($used_datastream_ids, $used_datastream->ID);
}
$unused_dsids = array();
if ($form_state['submitted'] && $form_state['clicked_button']['#value'] != 'OK') {
$form['add_datastream_label'] = array(
'#value' => t('<br /><h3>The datastream has been uploaded.</h3>'),
'#weight' => -10,
);
$form['#redirect'] = "fedora/repository/$pid/";
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('OK')
);
return $form;
}
if (!empty($available_dsids)) {
$unused_dsids = array_diff($available_dsids, $used_datastream_ids);
if (empty($unused_dsids)) {
return;
}
}
$form['add_datastream_label'] = array(
'#value' => t('<br /><h3>Add Datastream:</h3>'),
'#weight' => -10,
);
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
/*
$form['stream_location'] = array (
'#title' => 'File Location',
'#required' => 'TRUE',
'#description' => 'The path to the file for the new datastream',
//'#prefix' => '<a onclick="window.open(\'?q=imce/browse\', \'_imce_fedora_\', \'width=640, height=600, resizable=1\')" href="#">Upload File</a>',
'#type' => 'hidden'
);
*/
$form['stream_label'] = array(
'#title' => 'Datastream Label',
'#required' => 'TRUE',
'#description' => t('A Human readable label'),
'#type' => 'textfield'
);
// $form['delete_file'] = array (
// '#title' => 'Remove File After Ingest',
// '#description' => 'Remove the file from the drupal file system after ingest into the Digital Repository.',
// '#type' => 'hidden',
// '#default_value' => 'remove_file',
// '#options' => $options
// );
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['add-stream-file-location'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#size' => 48,
// '#required'=>'TRUE',
'#description' => t('The file to upload.')
);
$form['#redirect'] = "fedora/repository/$pid/";
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Datastream')
);
if (!empty($unused_dsids)) {
$form['stream_id'] = array(
'#type' => 'select',
'#title' => t('Datastream ID'),
'#default_value' => variable_get('feed_item_length', 'teaser'),
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
);
$form['stream_id']['#options'] = $unused_dsids;
}
else {
$form['stream_id'] = array(
'#title' => 'Datastream ID',
'#required' => 'TRUE',
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores.'),
'#type' => 'textfield',
'#weight' => -1,
);
}
return $form;
}
/**
* Creates a drupal form to edit either the QDC or DC datastream
*/
function createMetaDataForm($pid, $dsId = NULL, $client) {
if (!isset($dsId)) {
$dsId = 'QDC';
}
//$client = getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
$params = array('pid' => "$pid", 'dsID' => "$dsId", 'asOfDateTime' => "");
try {
$object = $client->__soapCAll('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) {
return array();
}
$content = $object->dissemination->stream;
$content = trim($content);
$doc = new DOMDocument();
if (!$doc->loadXML($content)) {
echo "error loading xml";
}
$oai_dc = $doc->getElementsByTagName('dc');
$dcItems = $oai_dc->item(0)->getElementsByTagName('*');
$form = array();
for ($i = 0; $i < $dcItems->length; $i++) {
$name = $dcItems->item($i)->nodeName;
if ($name == 'dc:description') {
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => 'textarea',
'#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3)
);
}
elseif ($name == 'dc:title') {
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => 'textfield',
'#required' => 'TRUE',
'#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3)
);
}
else {
if ($oai_dc->item(0)->nodeName != $dcItems->item($i)->parentNode->nodeName) {
$description = strstr($name, ':');
$form['app_' . "$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => 'textfield',
'#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($description, 1)
);
}
else {
$field_type = 'textfield';
$value = $dcItems->item($i)->nodeValue;
if ($name == 'dc:coverage') {
$value = '';
}
if ($name == 'dc:rights') {
$field_type = 'textarea';
}
$description = strstr($name, ':');
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => $field_type,
'#default_value' => $value,
'#description' => 'Dublin Core ' . substr($description, 1)
);
}
}
}
// $form['#redirect'] = "fedora/repository/$pid/";
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
$form['dsid'] = array(
'#type' => 'hidden',
'#value' => "$dsId"
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update Metadata'),
);
return $form;
}
/**
* Creates a form for replacing datastream
*/
function createReplaceDataStreamForm($pid, $dsId, $dsLabel, &$form_state) {
$form = array();
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#description' => t('The file to upload.')
);
$form['pid'] = array(
'#type' => 'value',
'#value' => $pid,
);
$form['dsId'] = array(
'#type' => 'value',
'#value' => $dsId,
);
$form['dsLabel'] = array(
'#type' => 'value',
'#value' => $dsLabel,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Replace Datastream')
);
return $form;
}
/*
function createReplaceDataStreamForm($pid, $dsId, &$form_state) {
$form = array();
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#description' => t('The file to upload.')
);
$form['pid'] = array(
'#type' => 'value',
'#value' => $pid,
);
$form['dsId'] = array(
'#type' => 'value',
'#value' => $dsId,
);
$form['submit']=array(
'#type' => 'submit',
'#value'=>t('Replace Datastream')
);
return $form;
}
*/
}