'vertical_tabs', '#weight' => 0, ); $form['general'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('General'), '#group' => 'biblio_settings', '#description' => '' ); $form['general']['biblio_rev'] = array( '#markup' => $version, ); $form['general']['biblio_base'] = array( '#type' => 'textfield', '#title' => t('Base URL'), '#size' => 20, '#default_value' => variable_get('biblio_base', 'biblio'), '#description' => t('This sets the base URL used to access the biblio module (e.g. /biblio ).') ); $form['general']['biblio_base_title'] = array( '#type' => 'textfield', '#title' => t('Biblio page title'), '#size' => 20, '#default_value' => variable_get('biblio_base_title', 'Biblio'), '#description' => t('The page title shown on the base URL.') ); $form['general']['biblio_rowsperpage'] = array( '#type' => 'textfield', '#title' => t('Number of results per page'), '#default_value' => variable_get('biblio_rowsperpage', 25), '#size' => 6, '#maxlength' => 6, '#description' => t('This sets the number of results that will be displayed per page.') ); $form['general']['biblio_view_only_own'] = array( '#type' => 'checkbox', '#title' => t('Restrict users such that they can only view their own biblio entries'), '#return_value' => 1, '#default_value' => variable_get('biblio_view_only_own', 0), '#description' => t('This option restricts the users capability to view biblio entries. They will only be able to see the entries which they have created and own.') ); $form['authors'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Authors'), '#group' => 'biblio_settings', '#description' => '' ); $form['authors']['biblio_auto_orphaned_author_delete'] = array( '#type' => 'checkbox', '#title' => t('Automatically delete orphaned authors'), '#return_value' => 1, '#default_value' => variable_get('biblio_auto_orphaned_author_delete', 0), '#description' => t('Orphaned authors are those which are no longer linked to any entries as the result of a biblio update or delete.') ); $form['authors']['biblio_init_auth_count'] = array( '#type' => 'textfield', '#title' => t('Number of contributor fields to initially display on the input form'), '#size' => 2, '#maxlength' => 2, '#default_value' => variable_get('biblio_init_auth_count', 4), '#description' => t('Increasing this value will increase the number of input fields displayed in the contributors section of the input form') ); $form['authors']['biblio_contrib_fields_delta'] = array( '#type' => 'textfield', '#title' => t('Number of fields added by the "Add more" button on the contributor input form'), '#size' => 2, '#maxlength' => 2, '#default_value' => variable_get('biblio_contrib_fields_delta', 2), '#description' => t('This number of blank fields will be added to the contributors section of the input form each time the "Add more" button is pressed.') ); $form['bibtex'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('BibTex settings'), '#group' => 'biblio_settings', '#description' => '' ); $form['bibtex']['biblio_hide_bibtex_braces'] = array( '#type' => 'checkbox', '#title' => t('Retain bibtex\'s {Protected} capitalization in the title string, but hide the braces on display'), '#return_value' => 1, '#default_value' => variable_get('biblio_hide_bibtex_braces', 0), '#description' => '' ); $form['block'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Block settings'), '#description' => '', '#group' => 'biblio_settings', ); $form['block']['biblio_rowsperblock'] = array( '#type' => 'textfield', '#title' => t('Number of results in the "New Publications" block'), '#default_value' => variable_get('biblio_rowsperblock', 4), '#size' => 2, '#maxlength' => 2, '#description' => t('This sets the number of results that will be displayed in the "New Publications" block.') ); $form['block']['biblio_block_order'] = array( '#type' => 'radios', '#title' => t('Order by'), '#default_value' => variable_get('biblio_block_order', 'n.created'), '#options' => array( 'n.created' => t('Date Created'), 'b.biblio_year' => t('Year Published') ) ); $result = db_query("SELECT b.name, bftd.title FROM {biblio_fields} b INNER JOIN {biblio_field_type} bt ON bt.fid=b.fid INNER JOIN {biblio_field_type_data} bftd ON bftd.ftdid=bt.ftdid WHERE bt.tid=0 ORDER by bftd.title ASC "); $schema = drupal_get_schema('biblio'); $keys = array_keys($schema['fields']); $options = array(); $options['nid'] = t('Node ID'); foreach ($result as $row) { $options[$row->name] = $row->title; } $form['citekey'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Citekey'), '#description' => t('You can alter citekey related settings here.'), '#group' => 'biblio_settings', ); $form['citekey']['biblio_display_citation_key'] = array( '#type' => 'checkbox', '#title' => t('Show citation key in results'), '#return_value' => 1, '#default_value' => variable_get('biblio_display_citation_key', 0), '#description' => t('This will output the citekey as the first item in the citation string') ); $form['citekey']['biblio_auto_citekey'] = array( '#type' => 'checkbox', '#title' => t('Auto generate citekeys if not given'), '#return_value' => 1, '#default_value' => variable_get('biblio_auto_citekey', 1), '#description' => t('This option will cause "citekey" entries to be automatically generated if a value is not provided.') ); $form['citekey']['biblio_citekey_prefix'] = array( '#type' => 'textfield', '#title' => t('Citekey prefix'), '#default_value' => variable_get('biblio_citekey_prefix', ''), '#size' => 10, '#maxlength' => 10, '#description' => t('This text will be combined with the field choosen below to form the auto generated citekey.') ); $form['citekey']['biblio_citekey_field1'] = array( '#type' => 'select', '#title' => t('Primary Citekey field'), '#default_value' => variable_get('biblio_citekey_field1', 'nid'), '#options' => $options, '#description' => t('Select the field to be used when generating citekeys.') ); $form['citekey']['biblio_citekey_field2'] = array( '#type' => 'select', '#title' => t('Secondary Citekey field'), '#default_value' => variable_get('biblio_citekey_field2', 'nid'), '#options' => $options, '#description' => t('If the field above has no value this field will be used.') ); // Allow only users to modify PHP code which have PHP block visibility permissions if (user_access('use PHP for block visibility')) { $form['citekey']['biblio_citekey_phpcode'] = array( '#type' => 'textarea', '#title' => t('PHP code for citekey generation'), '#default_value' => variable_get('biblio_citekey_phpcode', ''), '#description' => t('Advanced usage only: PHP code that returns the citekey. Should not include <?php ?> delimiters.') ); } $form['biblio_crossref'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('CrossRef Login Information'), '#group' => 'biblio_settings', ); $link_attrs = array('attributes' => array('target' => '_blank'), 'absolue' => TRUE); $form['biblio_crossref']['biblio_show_crossref_profile_form'] = array( '#type' => 'checkbox', '#title' => t('Allow users to override these settings on their "My account" page') , '#return_value' => 1, '#description' => t('If this is selected, a form similar to this section will be available to the user when they edit their own account information. This will allow them to override the global preferences set here.') , '#default_value' => variable_get('biblio_show_crossref_profile_form', '1') ); $form['biblio_crossref']['biblio_crossref_pid'] = array( '#type' => 'textfield', '#title' => t('CrossRef OpenURL Account ID'), '#default_value' => variable_get('biblio_crossref_pid', ''), '#description' => t('Enter your complimentary CrossRef OpenURL account ID which you can obtain here !url, OR enter your full CrossRef (colon separated) account:password combination.', array('!url' => l(t('OpenURL Account Request Form'), 'http://www.crossref.org/requestaccount/', $link_attrs))) ); $form['footnotes'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Footnotes'), '#description' => t('You can integrate with the !url module here.', array('!url' => l('footnotes', url("http://www.drupal.org/project/footnotes", array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE))))), '#group' => 'biblio_settings', ); if (!module_exists('footnotes')) { $additional_text = '
Fields which are grayed out on this page have been set to "common" on the !linktobiblioadmin page.
', array('!linktobiblioadmin' => l("admin/config/biblio/fields", "admin/config/biblio/fields"))); } else { $msg .= ' ' . t('Checking the "Common" box will add the field to all the different publication types. Checking "Required" will force the user to supply a value for the field, checking "Autocomplete" will enable AJAX type auto complete look up for the field when the user is entering data and the weight value changes the order which it is rendered on the form with smaller values floating to the top of the form.'); } $msg .= t('Finally, for each author field you can choose a set of author roles. Assigning different roles to authors within the same field, e.g. primary and secondary authors within the authors field, allows to theme them differently.'); $msg .= '[ ' . l(t('Add New Type'), 'admin/config/biblio/fields/type/new') . ' ]'; $output .= ' [ ' . l(t('Reset all types to defaults'), 'admin/config/biblio/fields/type/reset') . ' ]'; $output .= theme('table', array('header' => $header, 'rows' => $rows)); $output .= '
[ ' . l(t('Add New Type'), 'admin/config/biblio/fields/type/new') . ' ]'; $output .= ' [ ' . l(t('Reset all types to defaults'), 'admin/config/biblio/fields/type/reset') . ' ]'; return $output; } function biblio_admin_types_add_form() { $form['name'] = array( '#type' => 'textfield', '#title' => t('Type Name'), '#size' => 20, '#weight' => 1, '#required' => TRUE, '#maxlength' => 64 ); $form['description'] = array( '#type' => 'textfield', '#title' => t('Description'), '#size' => 60, '#weight' => 2, '#maxlength' => 255 ); $form['type_button'] = array( '#type' => 'submit', '#value' => t('Create New Type'), '#weight' => 3 ); return $form; } function biblio_admin_types_add_form_submit($form, & $form_state) { $values = $form_state['values']; $values['tid'] = variable_get('biblio_max_user_tid', '999') + 1; db_insert('biblio_types') ->fields($values) ->execute(); variable_set('biblio_max_user_tid', $values['tid']); for ($f = 1; $f <= 51; $f++) { $ft_vals = array( 'tid' => $values['tid'], 'fid' => $f, 'ftdid' => $f, 'cust_tdid' => $f, 'weight' => $f, 'visible' => 1, ); db_insert('biblio_field_type') ->fields($ft_vals) ->execute(); } // Fill contributor types. Use the first 4 defaults. for ($type = 1; $type <= 4; $type++) { $ct_vals = array( 'auth_category' => $type, 'biblio_type' => $values['tid'], 'auth_type' => $type, ); db_insert('biblio_contributor_type') ->fields($ct_vals) ->execute(); } // Refresh publication type string for translation. biblio_locale_refresh_types($values['tid']); drupal_goto('admin/config/biblio/fields/type'); } function biblio_admin_types_hide() { $args = func_get_args(); if ($args[0] > 0 && is_numeric($args[0])) { db_update('biblio_types') ->fields(array( 'visible' => 0)) ->condition('tid', $args[0]) ->execute(); } drupal_goto('admin/config/biblio/fields/type'); } function biblio_admin_types_show() { $args = func_get_args(); if ($args[0] > 0 && is_numeric($args[0])) { db_update('biblio_types') ->fields(array( 'visible' => 1)) ->condition('tid', $args[0]) ->execute(); } drupal_goto('admin/config/biblio/fields/type'); } function biblio_admin_types_delete_form() { $args = func_get_args(); if ($args[1] > 0 && is_numeric($args[1])) { $row = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = :tid ', array(':tid', $args[1]))->fetchObject(); $num_rows = db_query('SELECT COUNT(*) FROM {biblio} as b WHERE b.biblio_type = :btype', array(':btype', $row['tid']))->fetchField(); if ($num_rows) { $existing_msg = t('There are @count biblio entries of this type, you should change the type of these entries before proceeding otherwise they will be deleted', array( '@count' => $num_rows )); } $form['tid'] = array( '#type' => 'value', '#value' => $row->tid ); $output = confirm_form($form, t('Are you sure you want to delete the custom biblio type: %title ?', array( '%title' => $row->name )) . $existing_msg, $_GET['destination'] ? $_GET['destination'] : 'admin/config/biblio/fields/type', t('This action cannot be undone.'), t('Delete'), t('Cancel')); return $output; } else { drupal_goto('admin/config/biblio/fields/type'); } } function biblio_admin_types_delete_form_submit($form, & $form_state) { db_delete('biblio_types') ->condition('tid', $form_state['values']['tid']) ->execute(); db_delete('biblio_field_type') ->condition('tid', $form_state['values']['tid']) ->execute(); drupal_goto('admin/config/biblio/fields/type'); } function biblio_admin_types_reset_form() { $form['reset'] = array( '#type' => 'value', '#value' => 'reset' ); $output = confirm_form($form, t('Are you sure you want to reset ALL the field definitions to the defaults?'), $_GET['destination'] ? $_GET['destination'] : 'admin/config/biblio/fields/type', t('By doing this, you will loose all customizations you have made to the field titles, this action cannot be undone!'), t('Reset!'), t('Cancel')); return $output; } function biblio_admin_types_reset_form_submit($form, & $form_state) { module_load_include('install', 'biblio'); biblio_reset_types(); drupal_goto("admin/config/biblio/fields/type"); } /* * This functin is used by both the admin/config/biblio page and user profile page * - if $user is set, then it is being called from the user profile page */ function _biblio_get_user_profile_form($profile_user = FALSE) { global $user; $form = array(); $allow_edit = variable_get('biblio_show_user_profile_form', '1'); $allow_edit = $allow_edit || user_access('administer biblio'); if (!$profile_user) { $form['biblio_show_user_profile_form'] = array( '#type' => 'checkbox', '#title' => t('Allow users to override these settings on their "My account" page') , '#return_value' => 1, '#description' => t('If this is selected, a form similar to this section will be available to the user when they edit their own account information. This will allow them to override the global preferences set here.') , '#default_value' => variable_get('biblio_show_user_profile_form', '1') ); } $form['biblio_show_profile'] = array( '#type' => 'checkbox', '#title' => ($profile_user) ? t('Show my publications on my profile page') : t('Show publications on users profile pages'), '#return_value' => 1, '#disabled' => !$allow_edit, '#description' => ($profile_user) ? t('Selecting this will create a listing of your publications on your profile page') : t('This sets the site wide default, users may change this in their profile') ); if ($profile_user) { $form['biblio_show_profile']['#default_value'] = (isset($profile_user->data['biblio_show_profile'])) ? $profile_user->data['biblio_show_profile'] : variable_get('biblio_show_profile', '0'); } else { $form['biblio_show_profile']['#default_value'] = variable_get('biblio_show_profile', '0'); } $form['biblio_my_pubs_menu'] = array( '#type' => 'checkbox', '#title' => t('Show "My publications" item in the navigation menu'), '#disabled' => !$allow_edit, '#return_value' => 1, '#description' => '' ); if ($profile_user) { $form['biblio_my_pubs_menu']['#default_value'] = ((isset($profile_user->data['biblio_my_pubs_menu'])) ? $profile_user->data['biblio_my_pubs_menu'] : variable_get('biblio_my_pubs_menu', '0')); } else { $form['biblio_my_pubs_menu']['#default_value'] = variable_get('biblio_my_pubs_menu', '0'); } if ($profile_user) { $db_result = db_query("SELECT cd.lastname, cd.firstname, cd.initials, cd.cid FROM {biblio_contributor_data} cd ORDER by cd.lastname ASC "); $options = array(); $options[0] = t('(None)'); foreach ($db_result as $row) { $options[$row->cid] = "$row->lastname, $row->firstname $row->initials "; } if (isset($profile_user->data['biblio_id_change_count']) && $profile_user->data['biblio_id_change_count'] > 2) { $allow_edit = 0; $msg = t('This control has been disabled because the author mapping has been changed more than 3 times, please see your system administrator to have it reset.'); } else { $msg = t('This will link your profile to the selected author from the biblio database, then all publications containing this author to be displayed on your "Publications" tab.'); } $form['biblio_contributor_id'] = array( '#type' => 'select', '#title' => t('Link My Profile with this Author from the Biblio database'), '#default_value' => isset($profile_user->data['biblio_contributor_id']) ? $profile_user->data['biblio_contributor_id'] : 0, '#disabled' => ($user->uid == 1 || user_access('administer biblio')) ? FALSE : !$allow_edit, '#options' => $options, '#description' => $msg, ); $form['biblio_id_change_count'] = array( '#type' => 'textfield', '#size' => 2, '#title' => t('Drupal UserID to Biblio AuthorID mapping change count'), '#default_value' => isset($profile_user->data['biblio_id_change_count']) ? $profile_user->data['biblio_id_change_count'] : 0, '#disabled' => ($user->uid == 1 || user_access('administer biblio')) ? FALSE : TRUE, '#description' => 'When this value is >= 3, the user will no longer be able to change their author id mapping', ); $options = array(); $options['system'] = t('System default'); $options = array_merge($options, biblio_get_styles() ); $form['biblio_user_style'] = array( '#type' => 'radios', '#title' => t('Style'), '#default_value' => (isset($profile_user->data['biblio_user_style']) ? $profile_user->data['biblio_user_style'] : 'system'), '#options' => $options, '#description' => t('Set the bibliographic style of the "list" view.') ); } return $form; } function _biblio_get_user_doi_form($user) { $form['biblio_doi'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('CrossRef Login Information') ); $link_attrs = array('attributes' => array('target' => '_blank'), 'absolue' => TRUE); $form['biblio_doi']['biblio_crossref_pid'] = array( '#type' => 'textfield', '#title' => t('CrossRef OpenURL Account ID'), '#default_value' => isset($user->data['biblio_crossref_pid']) ? $user->data['biblio_crossref_pid'] : '', '#return_value' => 1, '#description' => t('Enter your complimentary CrossRef OpenURL account ID which you can obtain here !url, OR enter your full CrossRef (colon separated) account:password combination.', array('!url' => l(t('OpenURL Account Request Form'), 'http://www.crossref.org/requestaccount/', $link_attrs))) ); return $form; } function _biblio_get_user_openurl_form($user) { $form['openurl'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('OpenURL'), '#description' => t('You can set an openurl link here') ); $form['openurl']['biblio_baseopenurl'] = array( '#type' => 'textfield', '#title' => t('OpenURL Base URL'), '#size' => 95, '#default_value' => !empty($user->data['biblio_baseopenurl']) ? $user->data['biblio_baseopenurl'] : '', '#description' => t('This sets your base OpenURL gateway, which is used to generate OpenURL links. To implement a "Universal" OpenURL system, try using OCLC\'s OpenURL Resolver Registry gateway: http://worldcatlibraries.org/registry/gateway') ); $sid = "Biblio:" . variable_get('site_name', 'Drupal'); $form['openurl']['biblio_openurl_sid'] = array( '#type' => 'textfield', '#title' => t('OpenURL Site ID'), '#size' => 95, '#default_value' => !empty($user->data['biblio_openurl_sid']) ? $user->data['biblio_openurl_sid'] : '', '#description' => t('This sets your site name, some link resolvers will require a specific Site ID in order to process your requests.') ); return $form; } /* This function parses the module directory for 'style' files, loads them and * calls the info fuction to get some basic information like the short and long * names of the style */ function biblio_form_sort($a, $b) { $a_weight = (is_array($a) && isset($a['weight'])) ? $a['weight'] : 0; $b_weight = (is_array($b) && isset($b['weight'])) ? $b['weight'] : 0; if ($a_weight == $b_weight) { return 0; } return ($a_weight < $b_weight) ? -1 : 1; } function biblio_admin_get_query($name) { switch ($name) { case "author_dup" : return ('SELECT lastname, firstname, initials, COUNT(lastname) as cnt FROM {biblio_contributor_data} GROUP BY lastname, firstname, initials HAVING COUNT(*)>1 ORDER BY lastname ASC, firstname ASC, initials ASC '); break; case "author_by_name" : return ("SELECT lastname, cid FROM {biblio_contributor_data} where lastname LIKE '%s'"); break; case 'author_pub_count' : // return ('SELECT bd.lastname, b.cid,COUNT(*) AS cnt FROM {biblio_contributor} b, {biblio_contributor_data} bd WHERE bd.cid=b.cid GROUP BY b.cid HAVING cnt > 0 ORDER BY lastname ASC'); return ('SELECT bd.lastname, b.cid,COUNT(*) AS cnt FROM {biblio_contributor} b, {biblio_contributor_data} bd WHERE bd.cid=b.cid GROUP BY b.cid, bd.lastname HAVING COUNT(*) > 0 ORDER BY lastname ASC'); break; } } function biblio_admin_author_types_form($form, &$form_state, $op = NULL, $id = NULL) { switch ($op) { case 'edit': $type = db_query("SELECT * FROM {biblio_contributor_type_data} WHERE auth_type=:atype", array(':atype' => $id))->fetchObject(); $form['auth_type'] = array( '#type' => 'hidden', '#value' => $type->auth_type); //fall through and use the same form used for a new entry case 'new': $form['title'] = array( '#type' => 'textfield', '#title' => t('Type Name'), '#size' => 20, '#weight' => 1, '#default_value' => ($op == 'new' ? '' : $type->title), '#required' => TRUE, '#maxlength' => 64 ); $form['hint'] = array( '#type' => 'textfield', '#title' => t('Description'), '#size' => 60, '#weight' => 2, '#default_value' => ($op == 'new' ? '' : $type->hint), '#maxlength' => 255 ); $form['type_button'] = array( '#type' => 'submit', '#value' => ($op == 'new')? t('Create New Type') : t('Save'), '#weight' => 3, '#submit' => array('biblio_admin_author_types_form_submit') ); $form_state['redirect'] = 'admin/config/biblio/author/type'; return $form; break; case 'hide': break; default: } } function theme_biblio_admin_author_types_form($form) { // We need this complex query to realize author_types which are not in use (cid is NULL) $db_result = db_query("SELECT ctd.*, cid FROM {biblio_contributor_type_data} ctd LEFT JOIN {biblio_contributor} c ON ctd.auth_type = c.auth_type GROUP BY ctd.auth_type"); foreach ($db_result as $row) { $ops = l(t('edit'), 'admin/config/biblio/author/type/' . $row->auth_type . '/edit' ); if (!isset($row->cid) && $row->auth_type >= 10) { // allow delete only if type not in use $ops .= ' '; $ops .= l(t('delete'), 'admin/config/biblio/author/type/' . $row->auth_type . '/delete/'); } $rows[] = array( $row->auth_type, check_plain($row->title), check_plain($row->hint), $ops, ); } $header = array( t('Type Id'), t('Contributor Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '2') ); $output = '
[ ' . l(t('Add New Type'), 'admin/config/biblio/author/type/new') . ' ]'; $output .= theme('table', array('header' => $header, 'rows' => $rows)); $output .= '
[ ' . l(t('Add New Type'), 'admin/config/biblio/author/type/new') . ' ]'; // $output .= ' [ ' . l(t('Reset all types to defaults'), 'admin/config/biblio/authors/reset') . ' ]'; return $output; } function biblio_admin_author_types_form_submit($form, $form_state) { $record->title = $form_state['values']['title']; $record->hint = $form_state['values']['hint']; switch ($form['#id']) { case 'biblio-admin-author-types-form-new': $record->title = $form_state['values']['title']; $record->hint = $form_state['values']['hint']; drupal_write_record('biblio_contributor_type_data', $record); break; case 'biblio-admin-author-types-form-edit': $record->auth_type = $form_state['values']['auth_type']; drupal_write_record('biblio_contributor_type_data', $record, 'auth_type'); break; } } function biblio_admin_author_type_delete_confirm(&$form_state, $type_id) { $base = variable_get('biblio_base', 'biblio'); $type_data = db_query('SELECT * FROM {biblio_contributor_type_data} bctd WHERE bctd.auth_type = :tid ', array(':tid' => $type_id))->fetchObject(); $form['auth_type'] = array( '#type' => 'value', '#value' => $type_data->auth_type, ); return confirm_form($form, t('Are you sure you want to delete the author type: %title ?', array('%title' => $type_data->title)), isset($_GET['destination']) ? $_GET['destination'] : 'admin/config/biblio/author/type', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } function biblio_admin_author_type_delete_confirm_submit($form, &$form_state) { db_delete('biblio_contributor_type_data') ->condition('auth_type', $form_state['values']['auth_type']) ->execute(); db_delete('biblio_contributor_type') ->condition('auth_type', $form_state['values']['auth_type']) ->execute(); drupal_goto('admin/config/biblio/author/type'); } function biblio_admin_author_edit_form($form, &$form_state, $author_id) { $merge_options = $linked = array(); $author = db_query('SELECT * FROM {biblio_contributor_data} b WHERE b.cid = :aid ', array(':aid' => $author_id))->fetchObject(); if (!$author) { drupal_not_found(); return; } $base = variable_get('biblio_base', 'biblio'); $menu = menu_get_active_title(); $path = (strpos($_GET['q'], 'settings'))? 'admin/config/biblio/author' : $base . '/authors'; $form['cid'] = array( '#type' => 'value', '#value' => $author_id ); $users = db_query('SELECT uid,name FROM {users} WHERE uid>0 ORDER BY name'); $options[0] = t('(None)'); foreach ($users as $user) { $options[$user->uid] = $user->name; } $form['drupal_uid'] = array( '#type' => 'select', '#title' => t('Drupal User ID'), '#options' => $options, '#default_value' => $author->drupal_uid, '#weight' => 12, '#required' => FALSE, '#description' => t('If this author has a an account (Drupal User ID) on this web site, you may select it here. This will help to link the authors publications with other content.') ); $form['name'] = array( '#type' => 'textfield', '#title' => t('Complete Name'), '#default_value' => $author->name, '#size' => 100, '#weight' => 1, '#required' => TRUE, '#maxlength' => 128 ); $form['literal'] = array( '#type' => 'checkbox', '#title' => t('Do not reformat'), '#default_value' => $author->literal, '#weight' => 1.5, '#required' => FALSE, '#description' => t('Selecting this will prevent the styles from trying to reformat the contributor name. The text in the "Complete Name" field will be used as is.') ); $form['prefix'] = array( '#type' => 'textfield', '#title' => t('Prefix'), '#default_value' => $author->prefix, '#size' => 20, '#weight' => 2, '#required' => FALSE, '#maxlength' => 128 ); $form['firstname'] = array( '#type' => 'textfield', '#title' => t('First Name'), '#default_value' => $author->firstname, '#size' => 20, '#weight' => 3, '#required' => FALSE, '#maxlength' => 128 ); $form['initials'] = array( '#type' => 'textfield', '#title' => t('Initials'), '#default_value' => $author->initials, '#size' => 20, '#weight' => 4, '#required' => FALSE, '#maxlength' => 10 ); $form['lastname'] = array( '#type' => 'textfield', '#title' => t('Last Name'), '#default_value' => $author->lastname, '#size' => 20, '#weight' => 5, '#required' => TRUE, '#maxlength' => 128 ); $form['suffix'] = array( '#type' => 'textfield', '#title' => t('Suffix'), '#default_value' => $author->suffix, '#size' => 20, '#weight' => 6, '#required' => FALSE, '#maxlength' => 128 ); $form['affiliation'] = array( '#type' => 'textfield', '#title' => t('Affiliation'), '#default_value' => $author->affiliation, '#size' => 100, '#weight' => 7, '#required' => FALSE, '#maxlength' => 256, '#description' => t('University, Company or Organization that the author is affiliated with.') ); $authors = db_query("SELECT * FROM {biblio_contributor_data} cd WHERE cid != :aid ORDER BY lastname", array(':aid' => $author_id), array('fetch' => PDO::FETCH_ASSOC)); $base = variable_get('biblio_base', 'biblio'); foreach ($authors as $other_author) { if ((stripos($other_author['name'], $author->lastname) !== FALSE) && $author->aka != $other_author['cid']) { $merge_options[$other_author['cid']] = l($other_author['name'], $base . '/authors/' . $other_author['cid'] . '/edit/'); if ($other_author['affiliation']) $merge_options[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')'; } if ($other_author['aka'] != 0 && $author->cid == $other_author['aka'] || $author->aka == $other_author['cid']) { $linked[$other_author['cid']] = l($other_author['lastname'] . ($other_author['firstname'] ? ', ' . $other_author['firstname'] : ($other_author['initials']?', ' . $other_author['initials']:'')), $base . '/authors/' . $other_author['cid'] . '/edit/'); if ($other_author['affiliation']) $linked[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')'; $linked_default_values[] = $other_author['cid']; } else { $link_options[$other_author['cid']] = $other_author['lastname'] . ($other_author['firstname'] ? ', ' . $other_author['firstname'] : ($other_author['initials'] ? ', ' . $other_author['initials'] : '')); if ($other_author['affiliation']) $link_options[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')'; } } if (count($merge_options)) { $form['merge'] = array( '#type' => 'fieldset', '#title' => t('Author Merge'), '#description' => t('Select other author names which will be merged. Merging removes all the selected authors, then replaces any references to these authors with the author being edited above. You should only do this if you are sure the other authors represent the same author as the one being edited. THIS CANNOT BE UNDONE!'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => !count($merge_options), ); $form['merge']['merge_authors'] = array( '#type' => 'checkboxes', '#title' => t('Similar authors'), '#options' => $merge_options, '#weight' => 12, '#required' => FALSE, ); $form['merge']['merge'] = array( '#type' => 'submit', '#value' => t('Merge') ); } $form['link'] = array( '#type' => 'fieldset', '#title' => t('Author Link'), '#description' => t('Select other author names which will be linked. Linking relates all the selected authors to the author being edited above, and and keeps each instance in the database. You should only do this if you are sure the other authors represent the same author as the one being edited.'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => !count($linked), ); if (count($linked)) { $form['link']['linked_authors'] = array( '#type' => 'checkboxes', '#title' => t('This author has already been linked to these authors'), '#default_value' => $linked_default_values, '#options' => $linked, '#weight' => 12, '#required' => FALSE, ); } $form['link']['link_authors'] = array( '#type' => 'select', '#title' => t('Other authors which could be linked to this author'), //'#default_value' => $link_default_values, '#options' => $link_options, '#weight' => 12, '#required' => FALSE, '#multiple' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save') ); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel') ); return $form; } function biblio_admin_author_edit_form_validate($form, &$form_state) { foreach ($form_state['values'] as $key => $value) { if (is_string($value)) $form_state['values'][$key] = trim($value); } } function biblio_admin_author_edit_form_submit($form, &$form_state) { $op = $form_state['values']['op']; $merge_authors = FALSE; $link_authors = FALSE; $linked_authors = FALSE; switch ($op) { case t('Save'): case t('Merge'): if (isset($form_state['values']['merge_authors']) && $op == t('Merge')) { $merge_authors = array_filter($form_state['values']['merge_authors']); } if (isset($form_state['values']['linked_authors']) ) { $linked_authors = $form_state['values']['linked_authors']; } if (isset($form_state['values']['link_authors']) ) { $link_authors = $form_state['values']['link_authors']; } unset($form_state['values']['merge_authors']); unset($form_state['values']['link_authors']); unset($form_state['values']['linked_authors']); if ($form_state['values']['drupal_uid'] == 0 ) { $uid = $form['drupal_uid']['#default_value']; $cid = 0; } else { $uid = $form_state['values']['drupal_uid']; $cid = $form_state['values']['cid'] ; } if ($uid) { db_update('biblio_contributor_data') ->fields(array('drupal_uid' => 0)) ->condition('drupal_uid', $uid) ->execute(); $result = db_query('SELECT data FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchField(); $data = unserialize($result); $data['biblio_contributor_id'] = $cid; $v = serialize($data); db_update('users') ->fields(array('data' => $v)) ->condition('uid', $uid) ->execute(); } drupal_write_record('biblio_contributor_data', $form_state['values'], 'cid'); // db_update('biblio_contributor_data') // ->fields($form_state['values']) // ->execute(); // merge authors if ($merge_authors && count($merge_authors)) { db_update('biblio_contributor') ->fields(array('cid' => $form_state['values']['cid'])) ->condition('cid', $merge_authors, 'IN') ->execute(); db_delete('biblio_contributor_data') ->condition('cid', $merge_authors, 'IN') ->execute(); } if ($linked_authors) { foreach ($linked_authors as $key => $value) { if ($value == 0) { db_update('biblio_contributor_data') ->fields(array('aka' => $key)) ->condition('cid', $key) ->execute(); } } } if ($link_authors ) { //db_query("UPDATE {biblio_contributor_data} SET aka=$form_state['values']['cid'] WHERE cid IN ($authors)"); foreach ($link_authors as $key => $value) { db_update('biblio_contributor_data') ->fields(array('aka' => $form_state['values']['cid'])) ->condition('cid', $key) ->execute(); } } break; case t('Cancel'): break; } } function biblio_admin_orphans_form($form_state) { $form = array(); $base = variable_get('biblio_base', 'biblio'); /* TODO translate this query... it should be faster $result = pager_query('SELECT distinct d.cid cid, name, affiliation FROM {biblio_contributor_data} d LEFT JOIN {biblio_contributor} c ON (d.cid=c.cid) WHERE c.cid IS NULL', 50); */ $sub_query = db_select('biblio_contributor', 'bc'); $sub_query->fields('bc', array('cid')); $sub_query->groupBy('cid'); $query = db_select('biblio_contributor_data', 'bcd')->extend('PagerDefault')->limit(50); $query->fields('bcd'); // SELECT * FROM {biblio_contributor_data} $query->condition('cid', $sub_query, 'NOT IN'); $result = $query->execute(); //pager_query('SELECT * FROM {biblio_contributor_data} WHERE cid NOT IN (SELECT cid FROM {biblio_contributor} GROUP BY cid)', 50); $authors = array(); foreach ($result as $author) { $authors[$author->cid] = ''; $form['name'][$author->cid] = array('#value' => l($author->name, $base . '/authors/' . $author->cid . '/edit')); $form['affiliation'][$author->cid] = array('#value' => check_plain($author->affiliation)); } if (!empty($authors)) { $form['authors'] = array('#type' => 'checkboxes', '#options' => $authors); $form['pager'] = array('#value' => theme('pager', array('tags' => NULL, 'element' => 0))); $form['#theme'] = 'biblio_admin_orphans_form'; $form['submit'] = array( '#type' => 'submit', '#value' => t('Delete'), '#disabled' => (!count($authors)), '#submit' => array('biblio_admin_orphans_form_submit'), ); } return $form; } function biblio_admin_orphans_form_validate($form, &$form_state) { $check_count = array_filter($form_state['values']['authors']); if (count($check_count) == 0) { form_set_error('', t('No items selected.')); } } function biblio_admin_orphans_form_submit($form, &$form_state) { // Filter out unchecked authors $authors = array_filter($form_state['values']['authors']); db_delete('biblio_contributor_data') ->condition('cid', $authors, 'IN') ->execute(); drupal_set_message(t('The orphaned authors (@author_list) have been deleted.', array('@author_list', implode(',', $authors)))); } function biblio_admin_keyword_orphans_form($form, $form_state) { $base = variable_get('biblio_base', 'biblio'); /* TODO TRANSLATE THIS QUERY... $result = pager_query('SELECT distinct bkd.kid kid, word FROM {biblio_keyword_data} bkd LEFT JOIN {biblio_keyword} bk ON (bkd.kid=bk.kid) WHERE bk.kid IS NULL', 50); */ $sub_query = db_select('biblio_keyword', 'bk'); $sub_query->fields('bk', array('kid')); $sub_query->groupBy('kid'); $query = db_select('biblio_keyword_data', 'bkd')->extend('PagerDefault')->limit(50); $query->fields('bkd'); // SELECT * FROM {biblio_contributor_data} $query->condition('kid', $sub_query, 'NOT IN'); $result = $query->execute(); //pager_query('SELECT * FROM {biblio_keyword_data} WHERE kid NOT IN (SELECT kid FROM {biblio_keyword} GROUP BY kid)', 50); $keywords = array(); foreach ($result as $keyword) { $keywords[$keyword->kid] = ''; $form['keyword'][$keyword->kid] = array('#markup' => l($keyword->word, $base . '/keyword/' . $keyword->kid . '/edit')); } $form['keywords'] = array('#type' => 'checkboxes', '#options' => $keywords); $form['pager'] = array('#value' => theme('pager', array('tags' => NULL, 'element' => 0))); $form['#theme'] = 'biblio_admin_keyword_orphans_form'; $form['submit'] = array( '#type' => 'submit', '#value' => t('Delete'), '#disabled' => (!count($keywords)), '#submit' => array('biblio_admin_keyword_orphans_form_submit'), ); return $form; } function biblio_admin_keyword_orphans_form_validate($form, &$form_state) { $check_count = array_filter($form_state['values']['keywords']); if (count($check_count) == 0) { form_set_error('', t('No items selected.')); } } function biblio_admin_keyword_orphans_form_submit($form, &$form_state) { $keywords = array_filter($form_state['values']['keywords']); db_delete('biblio_keyword_data') ->condition('kid', $keywords, 'IN') ->execute(); $count = count($keywords); drupal_set_message(t('%count orphaned keywords have been deleted.', array('%count' => $count))); } function biblio_admin_keyword_edit_form($form, &$form_state, $keyword_id) { $base = variable_get('biblio_base', 'biblio'); $options = NULL; $keyword = db_query('SELECT * FROM {biblio_keyword_data} bkd WHERE bkd.kid = :kid ', array(':kid' => $keyword_id))->fetchObject(); $base = variable_get('biblio_base', 'biblio'); $path = (strpos($_GET['q'], 'settings')) ? 'admin/config/biblio/keywords' : $base . '/keywords'; $form_state['redirect'] = $path; $form['kid'] = array( '#type' => 'value', '#value' => $keyword_id ); $form['word'] = array( '#type' => 'textfield', '#title' => t('Keyword'), '#default_value' => $keyword->word, '#size' => 100, '#weight' => -10, '#required' => TRUE, '#maxlength' => 255 ); $keywords = db_query("SELECT * FROM {biblio_keyword_data} kd WHERE word LIKE :word AND kid!=:kid", array(':word' => '%%' . drupal_substr($keyword->word, 0, 5) . '%%', ':kid' => $keyword_id)); unset($options); $base = variable_get('biblio_base', 'biblio'); foreach ($keywords as $kw) { $options[$kw->kid] = l($kw->word, $base . '/keywords/' . $kw->kid . '/edit'); } if (isset($options) && !empty($options)) { $form['merge'] = array( '#type' => 'fieldset', '#title' => t('Keyword Merge'), '#description' => t('Select other keywords which will be merged with the one above. You should only do this if you are sure the other keywords represent the same keyword as the one being edited.'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['merge']['merge_keywords'] = array( '#type' => 'checkboxes', '#title' => t('Similar keywords'), '#options' => $options, '#weight' => 12, '#required' => FALSE, '#multiple' => TRUE, '#size' => min(count($options), 6), ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save') ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete') ); $form['cancel'] = array( '#type' => 'submit', '#value' => t('Cancel') ); return $form; } function theme_biblio_admin_keyword_edit_form($variables) { $form = $variables['form']; $output = drupal_render($form['word']); $output .= drupal_render($form['merge']); $output .= drupal_render_children($form); return $output; } function biblio_admin_keyword_delete_confirm($form, &$form_state, $keyword_id) { $base = variable_get('biblio_base', 'biblio'); $keyword = db_query('SELECT * FROM {biblio_keyword_data} bkd WHERE bkd.kid = :kid ', array(':kid' => $keyword_id))->fetchObject(); $form['kid'] = array( '#type' => 'value', '#value' => $keyword_id, ); return confirm_form($form, t('Are you sure you want to delete the keyword: %word from ALL publications?', array('%word' => $keyword->word)), isset($_GET['destination']) ? $_GET['destination'] : $base . '/keywords', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } function biblio_admin_keyword_delete_confirm_submit($form, &$form_state) { $base = variable_get('biblio_base', 'biblio'); module_load_include('inc', 'biblio', 'biblio.keywords'); biblio_delete_keyword($form_state['values']['kid']); drupal_goto($base . '/keywords'); } function biblio_admin_keyword_edit_form_submit($form, &$form_state) { switch ($form_state['values']['op']) { case t('Save'): drupal_write_record('biblio_keyword_data', $form_state['values'], 'kid'); if (isset($form_state['values']['merge_keywords'])) { $kids = array_filter($form_state['values']['merge_keywords']); if (count($kids)) { db_update('biblio_keyword') ->fields(array('kid' => $form_state['values']['kid'])) ->condition('kid', $kids, 'IN') ->execute(); db_delete('biblio_keyword_data') ->condition('kid', $kids, 'IN') ->execute(); } } break; case t('Delete'): $base = variable_get('biblio_base', 'biblio'); unset($_GET['destination']); drupal_goto("$base/keyword/" . $form_state['values']['kid'] . '/delete'); break; case t('Cancel'): $base = variable_get('biblio_base', 'biblio'); drupal_goto($base . '/keywords'); break; } }