-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscholar.module
213 lines (169 loc) · 6.25 KB
/
scholar.module
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
<?php
module_load_include('inc', 'scholar', 'IrClass');
function scholar_edit_refworks($pid) {
return drupal_get_form('scholar_edit_refworks_form', $pid);
}
function scholar_edit_refworks_form($form_state, $pid) {
$edit_refworks_form = new IrClass();
return $edit_refworks_form->buildRefworksEditForm($pid);
}
function scholar_edit_refworks_form_submit($form, &$form_state) {
$irClass = new IrClass();
$form_state['redirect'] = $irClass->updateRefworksMetaData($form_state['values']);
}
function scholar_full_record($pid) {
$irClass = new IrClass();
$output = $irClass->show_full_record($pid);
return $output;
}
function scholar_role($type, $query) {
$role = $query; //
$irClass = new IrClass();
//real bad hack to change home economics and ohters to something different (ldap groups are incorrect in ldap server so they say)
$department = $query;
if ('Home Economics' == $department) {
$department = 'Family and Nutritional Sciences';
}
else if ('Anatomy Physiology' == $department) {
$department = 'Biomedical Sciences';
}
else if ('Womens Studies' == $department) {
$department = "Women's Studies";
}
else if ('Path Micro' == $department) {
$department = "Pathology and Microbiology";
}
else if ('Soc Anth' == $department) {
$department = "Sociology and Anthropology";
}
$output = "<h4 align='center'>$department</h4>";
$usersArray = array();
$results = scholar_custom_search($type, $query, 0, 0, $usersArray);
$output.='<center><table class="table-form"><tr>' . drupal_get_form('scholar_browse_by_user_form', $role, $usersArray) . '</tr></table></center>';
return $output . $results;
}
function scholar_add_ir_datastream_form($form_state, $pid) {
$datastream_form = new IrClass();
return $datastream_form->build_add_datastream_form($pid);
}
function scholar_add_ir_datastream_form_submit($form, &$form_state) {
$ir = new IrClass();
$ir->addStreamFormSubmit($form_state['values']['form_id'], $form_state['values']);
}
function scholar_create_roles_for_users() {
$irClass = new IrClass();
$irClass->get_and_create_roles();
return 'created roles and associated users.';
}
/*
* defines the list of paths and hooks/callbacks for the scholar module
*/
function scholar_menu() {
$items = array();
$items['fedorair/ir'] = array(
'title' => 'Institutional Repository',
'page callback' => 'scholar_home',
'type' => MENU_NORMAL_ITEM,
'access callback' => 'user_access',
'access arguments' => array('view scholarly research'),
);
$items['fedorair/custom_search'] = array(
'title' => 'Institutional Repository',
'page callback' => 'scholar_custom_search',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('view scholarly research'),
);
$items['fedorair/advanced_search'] = array(
'title' => 'Institutional Repository Advanced Search',
'page callback' => 'scholar_advanced_search',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('view scholarly research'),
);
$items['fedorair/ir_role'] = array(
'title' => 'Institutional Repository By Department',
'page callback' => 'scholar_role',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('view scholarly research'),
);
$items['fedorair/ir_by_name'] = array(
'title' => 'Institutional Repository By User Name',
'page callback' => 'scholar_by_name',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('view scholarly research'),
);
$items['fedorair/ir_full_record'] = array(
'title' => 'Citation',
'page callback' => 'scholar_full_record',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('view scholarly research'),
);
$items['fedorair/ir_edit_refworks'] = array(
'title' => 'Edit Metadata',
'page callback' => 'scholar_edit_refworks',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('add scholarly research'),
);
$items['fedorair/ir_create_roles_for_users'] = array(
'title' => 'Edit Metadata',
'page callback' => 'scholar_create_roles_for_users',
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
'access arguments' => array('add scholarly research'),
);
return $items;
}
// end function ir_menu
/**
* Valid permissions for this module
* @return array An array of valid permissions for the IR module
*/
function scholar_perm() {
return array('view scholarly research', 'add scholarly research');
}
// end function scholar_perm()
function scholar_uninstall() {
return true; // there isn't really anything to uninstall
}
// end function scholar_uninstall
function fedora_repository_scholar_settings_page() {
}
function scholar_form_fedora_repository_ingest_form_alter(&$form, &$form_state) {
array_unshift($form['#validate'], 'validation_for_refworks');
$form['indicator']['ingest-file-location']['#title'] = t('Upload Refworks Document');
$form['indicator']['ingest-file-location']['#description'] = t('Upload refworks xml document containing one or more records.');
}
function validation_for_refworks($form, &$form_state) {
if ($form_state['clicked_button']['#id'] == 'edit-submit') {
switch ($form_state['storage']['step']) {
case 1:
$form_state['rebuild'] = TRUE;
break;
case 2:
// Get the uploaded file.
$validators = array();
if (!empty($_FILES['files']['name']['pdf-file-location'])) {
$fileObject = file_save_upload('pdf-file-location', $validators);
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['pdf-file-location'] = $fileObject->filepath;
}
if (file_exists($form_state['values']['pdf-file-location'])) {
$file = $form_state['values']['pdf-file-location'];
$extention = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($extention!='pdf') {
form_set_error('pdf-file-location', t("$file does not appear to be a valid PDF."));
file_delete($file);
return;
}
}
$form_state['rebuild'] = FALSE;
break;
}
}
}
?>