Newer
Older
<?php
/**
* @file
* XC module functions
*
* @copyright (c) 2010-2011 eXtensible Catalog Organization
*/
/**
* Implements hook_permission().
*/
function xc_permission() {
return array(
'administer xc' => array(
'title' => t('administer xc'),
'description' => t('Administer eXtensible Catalog'),
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
),
);
}
/**
* Implements hook_menu().
*/
function xc_menu() {
$items['admin/xc'] = array(
'title' => 'eXtensible Catalog (XC)',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer xc'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/xc/common'] = array(
'title' => 'Common functions',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer xc'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/xc/common/setup_checklist'] = array(
'title' => 'Setup checklist',
'description' => 'Check that whether every necessary component has been set correctly.',
'page callback' => 'xc_setup_checklist',
'access arguments' => array('administer xc'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/xc/common/turn_on_alerts'] = array(
'title' => 'Turn on alerts',
'description' => 'If the site admin is alerted once, the site will not report the problem again. After he solve the problem, he have to turn this feature on, to activate email sending',
'page callback' => 'drupal_get_form',
'page arguments' => array('xc_turn_on_alerts_form'),
'access arguments' => array('administer xc'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_menu_link_alter().
*
* @param $item (Array)
* Reference to menu item to choose
*/
function xc_menu_link_alter(&$item) {
if ($item['link_path'] == 'xc/login') {
$item['options']['query'] = drupal_get_destination();
}
}
/**
* Implements hook_menu_alter().
*
* Changes the user/view menu's title from View to View My Account
*
* @param $items (Array)
* Reference to the menu items
*/
function xc_menu_alter(&$items) {
// TODO: this should be optional.
// 1) create an admin form
// 2) use variable_get('xc_user_view_link_title', 'View My Account');
$items['user/%user/view']['title'] = 'View My Account';
}
/**
* Wrapper function for the drupal_set_message, which write a message
* to the top of the current page
*
* @param $module
* The name of the module, which sends message
* @param $message
* The content of message
* @param $type
* The type of message {@see drupal_set_message}
*/
function xc_set_message($module, $message, $type = 'error') {
drupal_set_message(filter_xss('<strong>' . $module . ':</strong> ' . $message), $type);
}
/**
* Theme preprocessor used to place selector in body classes for easier theming.
*
* Adds tab-xc-search, tab-xc-browse or tab-my-admin depending different criteria.
* The purpose is to notify the HTML which XC tab should be utilized.
*
* @param $variables
*/
function xc_preprocess_page(&$variables) {
global $_xc_search_no_results;
// get existing classes of <body> element
// TODO: in D7 body_classes has not the same meaning as in D6
if (isset($variables['body_classes'])) {
$body_classes = explode(' ', $variables['body_classes']);
}
else {
$body_classes = array();
}
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
$active_link = 'xc/search';
$xc_class = '';
if (!$_xc_search_no_results && preg_match('{^admin\/xc\/search\/full\b}', $_GET['q'])
|| (arg(0) == 'node'
&& in_array('node-type-xc-manifestation', $body_classes))) {
if (isset($_GET['caller'])
&& in_array($_GET['caller'], array('xc-browse', 'xc-search', 'my-account'))) {
$xc_class = 'tab-' . $_GET['caller'];
switch ($_GET['caller']) {
case 'xc-browse':
$browse_commons = xc_browse_cache('browse_commons');
if (!is_null($browse_commons)) {
$active_link = 'xc_browse/' . $browse_commons->args[1];
}
break;
case 'my-account':
$active_link = 'xc/search';
break;
case 'xc-search':
default:
$active_link = 'xc/search';
break;
}
}
}
elseif (!$_xc_search_no_results &&
preg_match('{^(search\/xc_search|xc\/search)\b}', $_GET['q'])) {
$xc_class = 'tab-xc-search';
$active_link = 'xc/search';
}
elseif (arg(0) == 'xc_browse') {
$xc_class = 'tab-xc-browse';
$active_link = 'xc_browse/' . arg(1);
}
elseif (arg(0) == 'user') {
$xc_class = 'tab-my-account';
$active_link = 'xc/search';
}
elseif (arg(0) == 'demo-login') {
$xc_class = 'tab-login';
$active_link = 'xc/search';
}
elseif ($_GET['q'] == 'admin/xc/search/more_facets') {
$xc_class = 'tab-xc-search';
$active_link = 'xc/search';
}
elseif (arg(0) == 'admin') {
$xc_class = 'tab-admin';
$active_link = 'xc/search';
}
$variables['active_xc_primary_link'] = $active_link;
$body_classes[] = $xc_class;
$variables['body_classes'] = implode(' ', array_unique($body_classes));
// display primary tabs in we come from browse to node
if (arg(0) == 'node' && isset($_GET['caller']) && $_GET['caller'] == 'xc-browse') {
$tabs_primary = xc_browse_cache('tabs_primary');
if ($tabs_primary) {
// Add browse' primary local tasks tab
$variables['browse_tabs'] = $tabs_primary;
}
}
}
/**
* Gets the checklist of the important XC settings
*
* It provides a help to admin what and where to set in order to achive a properly working site
*/
function xc_setup_checklist() {
$output = '';
// intro
$output .= '<p>' . t('The following list informs you about the readiness of eXtensible Catalog module for using. This list does not guarantee, that every settings is correct, and everything will work fine, since here the Toolkit does not check the consistency of the values, only the existence of some settings. But in case of trouble it helps you to find a possible cause.') . '<p>';
// The container of the check results
$check_items = array();
// images
$status_ok = theme('image', array('path' => 'misc/watchdog-ok.png', 'width' => '', 'height' => '', 'alt' => t('ok'), 'title' => t('ok')));
$status_warning = theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => '', 'height' => '', 'alt' => t('warning'), 'title' => t('warning')));
$status_error = theme('image', array('path' => 'misc/watchdog-error.png', 'width' => '', 'height' => '', 'alt' => t('error'), 'title' => t('error')));
$xc_modules = array(
'xc',
'xc_util',
'xc_metadata',
'xc_sql',
'xc_schema',
'ncip',
'xc_ncip_provider',
'oaiharvester',
'xc_oaiharvester_bridge',
'xc_external',
'syndetics',
'xc_account',
'xc_auth',
'xc_ils',
'xc_import_export',
'xc_oai_dc',
'xc_solr',
'xc_index',
'xc_search',
'ezproxy_url_rewrite',
'xc_browse',
'xc_statistics',
'xc_dewey',
'xc_xissn',
'xc_wordnet',
);
$disabled_modules = array();
$unexistent_tables = array();
foreach ($xc_modules as $xc_module) {
if (!module_exists($xc_module)) {
$disabled_modules[] = $xc_module;
}
else {
module_load_include('install', $xc_module);
$schema = module_invoke($xc_module, 'schema');
if (empty($schema)) {
continue;
}
foreach ($schema as $table => $table_def) {
if (!db_table_exists($table)) {
$unexistent_tables[] = $table;
}
}
}
}
if (!empty($disabled_modules)) {
$list = array();
foreach ($disabled_modules as $module) { // edit-status-xc-import-export
$info = unserialize(db_query("SELECT info FROM {system} WHERE name = :name AND type = :type", array(':name' => $module, ':type' => 'module'))->fetchField());
$list[] = l($info['name'], 'admin/modules/list', array('fragment' => 'edit-status-' . str_replace('_', '-', $module)));
}
$check_items[] = array(
$status_warning,
format_plural(count($list),
'The following module is not installed: !list. You can install it at the !module_page.',
'The following modules are not installed: !list. You can install them at the !module_page.',
array(
'!list' => join(', ', $list),
'!module_page' => l(t('module page'), 'admin/modules/list'),
)),
);
}
else {
$check_items[] = array($status_ok, t('All XC modules are installed.'));
}
if (!empty($unexistent_tables)) {
$check_items[] = array(
$status_error,
t('The following tables are missing: !list', array('!list' => join(', ', $unexistent_tables))),
);
}
else {
$check_items[] = array($status_ok, t('All XC database tables are installed.'));
}
// check storage locations
$locations = xc_location_get_all();
if (!empty($locations)) {
$problems = array();
foreach ($locations as $location) {
if (!is_array($location->types)) {
$problems[] = t('%location_name location has only one storage type, the other is missing. Edit !location_link.',
array(
'%location_name' => $location->name,
'!location_link' => l(t('location'), 'admin/xc/metadata/location/' . $location->id),
));
}
if (!$location->has_solr_type) {
$problems[] = t('%location location does not store records into Solr. Edit !location_link.',
array(
'%location' => $location->name,
'!location_link' => l(t('location'), 'admin/xc/metadata/location/' . $location->id),
));
}
}
if (!empty($problems)) {
$check_items[] = array($status_error, theme('item_list', array('items' => $problems)));
}
else {
$check_items[] = array($status_ok, t('<em>Storage locations</em> are available to use.'));
}
}
else {
$title = t('Create storage locations');
$items = array(
t('goto !admin › !xc › !metadata › !location › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!metadata' => l(t('Metadata Storage Configuration and Utilities'), 'admin/xc/metadata'),
'!location' => l(t('Storage locations'), 'admin/xc/metadata/location'),
'!add' => l(t('Add storage location'), 'admin/xc/metadata/location/add'),
)),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Name:</em> default'),
t('<em>Description:</em> default location'),
))),
t('click <em>Continue</em>'),
t('accept everything as is if the Solr runs on the default <em>host</em>, <em>port</em> and <em>path</em>. Modify the default values, if your Solr instance is customized'),
t('click <em>Add storage location</em>'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
require_once drupal_get_path('module', 'xc_metadata') . '/includes/xc_metadata.format.inc';
// check formats
$formats = xc_format_get();
if (!empty($formats)) {
require_once drupal_get_path('module', 'xc_metadata') . '/includes/xc_metadata.format.inc';
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
$disabled_formats = array();
foreach ($formats as $type => $format) {
if (!xc_format_is_enabled($type)) {
$disabled_formats[] = $format['name'];
}
}
if (!empty($disabled_formats)) {
$check_items[] = array(
$status_warning,
t('The metadata schemas are disabled: %formats. You should enable these !here if you want to use them.',
array(
'%formats' => join(', ', $disabled_formats),
'!here' => l(t('here'), 'admin/xc/metadata/format'),
)),
);
}
else {
$check_items[] = array($status_ok, t('<em>Metadata schemas</em> are available.'));
}
}
else {
$check_items[] = array($status_error, t('There are no metadata schema available for XC Drupal Toolkit. You must first !install a schema module.',
array('!install' => l(t('install'), 'admin/modules'))));
}
// Checking registered NCIP providers
$ncip_providers = xc_ncip_provider_get_all();
if (!empty($ncip_providers)) {
$check_items[] = array($status_ok, t('<em>NCIP servers</em> are available to use.'));
}
else {
$title = t('Setup NCIP');
$items = array(
t('goto !admin › !xc › !ncip › !provider › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!ncip' => l(t('NCIP servers'), 'admin/xc/ncip'),
'!provider' => l(t('NCIP servers'), 'admin/xc/ncip/provider'),
'!add' => l(t('Add NCIP server'), 'admin/xc/ncip/provider/add'),
)),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Name</em>: the library name, which provide the NCIP interface (like "Rush Rhees Library")'),
t('<em>Description</em>: any convenient description about the service or the library'),
t('<em>Host</em>: the host IP or server name'),
t('<em>Port</em>: the port number'),
t('<em>Path</em>: the path part of NCIP (like "/NCIPToolkit_v0.3/")'),
)))
. t('<em>To Agency Id</em> section')
. theme('item_list', array('items' => array(
t('<em>Scheme</em>: an agency scheme\'s URL'),
t('<em>Value</em>: the name of the scheme owner (like "University of Rochester")'),
))),
t('click <em>Add NCIP server</em>'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
// checking registrated OAI-PMH data repositories
$provider_count = count(oaiharvester_provider_get_all_names());
if ($provider_count > 0) {
$check_items[] = array($status_ok, t('<em>OAI-PMH repositories</em> are available to harvest.'));
}
else {
$title = t('Register an OAI-PMH repository');
$items = array(
t('goto !admin › !xc › !harvester › !repository › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!harvester' => l(t('Metadata Harvester'), 'admin/xc/harvester'),
'!repository' => l(t('Repositories'), 'admin/xc/harvester/repository'),
'!add' => l(t('Add repository'), 'admin/xc/harvester/repository/add'),
)),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Name</em>: the name of the OAI-PMH repository'),
t('<em>Url</em>: The base url of the OAI-PMH service'),
))),
t('click <em>Submit and validate</em>'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
// Check ILS mapping
$bibid_mappings = xc_ils_get_all_mappings();
if (!empty($bibid_mappings)) {
$check_items[] = array($status_ok, t('<em>Integrated Library Systems </em> are configured.'));
}
else {
$title = t('Setup Integrated Library Systems (ILS) to connect metadata records to NCIP servers for circulation status, call number, and other information.');
$items = array(
t('goto !admin › !xc › !ils › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!ils' => l(t('ILS (NCIP) Record Mapping Settings'), 'admin/xc/ils'),
'!add' => l(t('Add'), 'admin/xc/ils/add'),
)),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>NCIP server</em>: select an NCIP server from the list'),
t('<em>Bib identifier field</em>: any field which identify the bib record (like "xc:recordID|@type=NRU" in the XC record XML schema)'),
))),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
// check authentication
if (module_exists('xc_auth')) {
$auth_types = xc_auth_type_get_all();
if (empty($auth_types)) {
$title = t('No login forms are available. Create login forms.');
$items = array(
t('goto !admin › !xc › !auth › !type › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!auth' => l(t('Authentication'), 'admin/xc/auth'),
'!type' => l(t('Login forms'), 'admin/xc/auth/type'),
'!add' => l(t('Add login form'), 'admin/xc/auth/type/add'),
)),
t('select an <em>Authentication method</em>'),
t('click on <em>Continue</em> button'),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Name</em>: the name of the the authentication type (examples are NetID, Barcode)'),
t('<em>Description</em>: provide a short description here'),
t('<em>Labels and Help Text</em>: customize the login form here'),
t('<em>NCIP Server and Authentication Type</em>: settings regarding NCIP'),
t('<em>Permissions automatically applied to new uers</em>: settings regarding to roles'),
))),
t('click <em>Add login form</em> button'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
else {
$check_items[] = array($status_ok, t('Login forms configured.'));
}
$login_blocks = xc_auth_login_block_get_all();
if (empty($login_blocks)) {
$title = t('No login blocks or pages exist on this system. Add a login block and page.');
$items = array(
t('goto !admin › !xc › !auth › !block › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!auth' => l(t('Authentication'), 'admin/xc/auth'),
'!block' => l(t('Login blocks and pages'), 'admin/xc/auth/block'),
'!add' => l(t('Add login blocks and pages'), 'admin/xc/auth/block/add'),
)),
t('select a <em>Login block type</em>'),
t('click on <em>Continue</em> button'),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Name</em>: the name of the the login form (like "Default login page")'),
t('<em>Description</em>: provide a short description'),
t('<em>URL alias</em>: provide the Drupal URL alias for the login page.'),
))),
t('click on <em>Continue</em> button'),
t('fill all addtional forms'),
t('click <em>Save</em> button'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
else {
$check_items[] = array($status_ok, t('Login forms and pages configured.'));
}
}
// check harvest schedule
$has_schedule = (boolean) db_query('SELECT count(*) FROM {oaiharvester_harvester_schedules}')->fetchField();
if ($has_schedule) {
$check_items[] = array($status_ok, t('<em>Scheduled harvests</em> are available.'));
}
else {
$title = t('Create a scheduled harvest.');
$items = array(
t('goto !admin › !xc › !harvester › !schedule › !add',
array(
'!admin' => l(t('Administer'), 'admin'),
'!xc' => l(t('eXtensible Catalog (XC)'), 'admin/xc'),
'!harvester' => l(t('Metadata Harvester'), 'admin/xc/harvester'),
'!schedule' => l(t('Scheduled harvests'), 'admin/xc/harvester/schedule'),
'!add' => l(t('Add scheduled harvest'), 'admin/xc/harvester/schedule/step1'),
)),
t('fill the form:')
. theme('item_list', array('items' => array(
t('<em>Select repository</em>: select from the list'),
t('<em>Schedule</em>: select hourly, daily, or weekly.'),
))),
t('click <em>Next</em>'),
t('fill the form:')
. theme('item_list', array('items' => array(
t('Choose Metadata Format: any format the OAI data provider supports'),
t('Choose Set: you can choose a given set, or select none, which will harvest all records'),
t('Choose Parsing Mode: Regular expression based if the response contains lots of records (hundreds). Otherwise you can choose the default DOM based process. Regex method is much more faster, but DOM is more reliable. Except extraordinary case regex is suggested. If you run into a problem with the regex method, please contact us, and choose DOM.'),
t('Do harvester cache responses? It is useful only in testing phase, but could be misleading in a production server, because it does not reflect the changes on the OAI-PMH server. If you do not want to use the cache more, set it to now, and delete the cache directory. It is the default file directory\'s oaiharvester_http_cache subdirectory.)'),
t('Storage locations: these are the storages you set up as the first step in this list. Choose at least one location, if you would like our module handle records.'),
t('Run "preparing metadata for search" step? Check this if you want to index records with Solr.'),
))),
t('Click <em>Submit</em>'),
);
$check_items[] = array($status_error, theme('item_list', array('items' => $items, 'title' => $title, 'type' => 'ol')));
}
$roles_without_permissions = array();
$result = db_query('SELECT * FROM {role_permission}');
$permission_collector = array();
foreach ($result as $permission) {
if (!isset($permission_collector[$permission->rid])) {
$permission_collector[$permission->rid] = array();
}
if (!in_array($permission->permission, $permission_collector[$permission->rid])) {
$permission_collector[$permission->rid][] = $permission->permission;
}
}
foreach ($permission_collector as $rid => $permissions) {
if (!in_array('access metadata', $permissions)) {
$name = db_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchField();
if (!in_array($name, $roles_without_permissions)) {
$roles_without_permissions[] = $name;
}
}
}
if (empty($roles_without_permissions)) {
$check_items[] = array($status_ok, t('All roles can access XC metadata.'));
}
else {
t('The following roles cannot access XC metadata: %names. You can set permissions at <em>xc_metadata module</em> section of !permission_page.', array(
'%names' => join(', ', $roles_without_permissions),
'!permission_page' => l(
t('permission administration page'),
array('fragment' => 'module-xc_metadata')),
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
)));
}
$tables_with_default_values = array(
'xc_browse' => array(
'xc_browse_ui',
'xc_browse_tab',
'xc_browse_element',
'xc_browse_list',
),
'xc_index' => array(
'xc_index_attribute_to_field',
'xc_index_field_to_facet',
'xc_index_field_type',
'xc_index_super_location',
'xc_index_sortable_field',
'xc_index_facet',
),
'xc_metadata' => array(
'xc_location',
),
'xc_search' => array(
'xc_search_mlt',
'xc_search_highlighter',
'xc_search_date_facet_properties',
'xc_search_field_facet_properties',
'xc_search_facet_group',
'xc_search_facet_field',
'xc_search_ui',
'xc_search_sortoption',
'xc_search_location',
),
'xc_solr' => array(
'xc_solr_field_type',
'xc_solr_servers',
),
'xc_sql' => array(
'xc_sql_storage',
),
);
$not_populated = array();
foreach ($tables_with_default_values as $module => $tables) {
foreach ($tables as $table) {
// TODO Please convert this statement to the D7 database API syntax.
$populated = (boolean) db_query('SELECT count(*) FROM {' . $table . '}')->fetchField();
if (!$populated) {
$not_populated[$module][] = $table;
}
}
}
if (empty($not_populated)) {
$check_items[] = array($status_ok, t('All default values were successfully imported into the appropriate tables.'));
}
else {
$check_items[] = array($status_error, t('The default values for the following modules were not successfully imported into the appropriate tables: @modules', array('@modules' => join(', ', array_keys($not_populated)))));
}
if (module_exists('xc_metadata')) {
require_once drupal_get_path('module', 'xc_metadata') . '/includes/xc_metadata.location.inc';
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
$locations = xc_location_get_all();
$pings = xc_solr_ping($locations);
foreach ($pings as $ping) {
if (!$ping['running']) {
$check_items[] = array($status_error, t('Solr at @url is not running. Please start this Apache Solr instance.', array('@url' => $ping['url'])));
}
else {
$check_items[] = array($status_ok, t('Solr at @url is running', array('@url' => $ping['url'])));
}
}
}
if (module_exists('xc_wordnet')) {
global $_xc_wordnet;
if (!isset($_xc_wordnet)) {
xc_wordnet_init_solr();
}
if (is_null($_xc_wordnet)) {
$check_items[] = array($status_error, t('Solr for WordNet is not set correctly. Please go to the WordNet integration !admin_page and register it.',
array('!admin_page' => l(t('administration page'), 'admin/xc/wordnet/settings'))));
}
else {
$result = $_xc_wordnet->ping();
if (!$result) {
$check_items[] = array($status_error, t('Solr for Wordnet at @url is not running. Please start this Apache Solr instance.', array('@url' => $_xc_wordnet->getUrl())));
}
else {
$check_items[] = array($status_ok, t('Solr for Wordnet at @url is running.', array('@url' => $_xc_wordnet->getUrl())));
}
}
}
// TODO: variable_get('syndetics_client_code', ''), and other variable_get..
if (module_exists('syndetics')) {
if (variable_get('syndetics_client_code', FALSE) === FALSE) {
$check_items[] = array($status_warning, t('The institutional code for Syndetics Solution has not been registered. Configure it in !syndetics_page',
array('!syndetics_page' => l(t('Syndetics Solution Services settings page'), 'admin/xc/syndetics'))));
}
else {
$check_items[] = array($status_ok, t('The institutional code for Syndetics Solution is already set.'));
}
}
$output .= theme('table', array('header' => array(t('status'), t('message')), 'rows' => $check_items));
return $output;
}
/**
* Get an XC settings
*
* @param $name (string)
* The field name
* @param $default (mixed)
* A default value if there is no such a field in xc_settings table
*/
function xc_settings_get($name, $default) {
$xc_settings = db_query('SELECT * FROM {xc_settings} WHERE id = :id', array(':id' => 1))->fetchObject();
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
if (isset($xc_settings->$name)) {
return $xc_settings->$name;
}
else {
return $default;
}
}
/**
* Set an XC settings
*
* @param $name (string)
* The key
* @param $value
* Any valid value regarding to the field definition
*/
function xc_settings_set($name, $value) {
$schema = drupal_get_schema('xc_settings');
if (isset($schema['fields'][$name])) {
// $xc_settings = db_fetch_object(db_query('SELECT * FROM {xc_settings} WHERE id = 1'));
// $xc_settings->$name = $value;
if ($schema['fields'][$name]['type'] == 'int') {
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("UPDATE {xc_settings} SET %s = %d WHERE id = 1", $name, $value) */
db_update('xc_settings')
->fields(array(
'%s' => $name,
))
->condition('id', 1)
->execute();
}
else {
// TODO Please review the conversion of this statement to the D7 database API syntax.
/* db_query("UPDATE {xc_settings} SET %s = '%s' WHERE id = 1", $name, $value) */
db_update('xc_settings')
->fields(array(
'%s' => $name,
))
->condition('id', 1)
->execute();
}
// drupal_write_record('xc_settings', $xc_settings, 'id');
}
else {
xc_log_error('xc', 'Usage of undefined field ' . $name . ' in xc_settings_set()');
}
}
/**
* Form to set the xc_ncip_provider_admin_alerted to 0 if it is not 0 already.
*
* @param $form_state (array)
* The FAPI form state
*/
function xc_turn_on_alerts_form($form, &$form_state) {
$alerted = xc_settings_get('xc_ncip_provider_admin_alerted', 0);
if ($alerted) {
$form['message'] = array(
'#type' => 'item',
'#markup' => t('If the site admin is alerted once, the site will not report the problem again. After he solve the problem, he have to turn this feature on, to activate email sending.'),
);
return confirm_form($form, t('Do you want to turn on alerts?'), '', '', t('Activate alerting email again'), t('Cancel'));
}
else {
$form['message'] = array(
'#type' => 'item',
'#markup' => t('The site admin has not been alerted recently, so no action needed this time.'),
);
return $form;
}
}
/**
* Handles the xc_turn_on_alerts_form submission.
*
* Sets the xc_ncip_provider_admin_alerted to 0, which means, that in case of problems
* the admin can be alerted by email again.
*
* @param $form (array)
* @param $form_state (array)
*/
function xc_turn_on_alerts_form_submit($form, &$form_state) {
xc_settings_set('xc_ncip_provider_admin_alerted', 0);
}