$version, ); $form['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['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['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['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['block'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Block settings'), '#description' => '' ); $form['block']['biblio_block_title'] = array( '#type' => 'textfield', '#title' => t('Title for the "New Publications" block'), '#default_value' => variable_get('biblio_block_title', 'New Publications'), '#size' => 40, '#maxlength' => 40, '#description' => '' ); $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, {biblio_field_type} bt, {biblio_field_type_data} bftd WHERE bt.fid=b.fid AND bftd.ftdid=bt.ftdid AND bt.tid=0 ORDER by bftd.title ASC "); $schema = drupal_get_schema('biblio'); $keys = array_keys($schema['fields']); $choice = new stdClass(); $choice->option = array( 'nid' => t('Node ID') ); $options[0] = $choice; while ($row = db_fetch_array($result)) { $fields[$row['name']] = $row; $choice = new stdClass(); $choice->option = array( $row['name'] => $row['title'] ); $options[] = $choice; } $form['citekey'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Citekey'), '#description' => t('You can alter citekey related settings here.') ); $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.') ); $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))))) ); if (!module_exists('footnotes')) { $additional_text = '
'. t('Fields which are grayed out on this page have been set to "common" on the '); $msg .= l("admin/settings/biblio/defaults", "admin/settings/biblio/defaults"); $msg .= t(' page.'); } else { $msg .= t('Checking the "Common" box will add the field to all the differnet 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 .= '
[ '. l(t('Add New Type'), 'admin/settings/biblio/types/new') .' ]'; $output .= ' [ '. l(t('Reset all types to defaults'), 'admin/settings/biblio/types/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; drupal_write_record('biblio_types', $values); 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 ); drupal_write_record('biblio_field_type', $ft_vals); } // Fill contributor types. Use the first 4 defaults. // $ct_id = array_shift(db_fetch_array(db_query('SELECT max(ct_id) from {biblio_contributor_type}'))); for ($type = 1; $type <= 4; $type++) { $ct_vals = array ( // 'ct_id' => $ct_id + $type, 'auth_catagory' => $type, 'biblio_type' => $values['tid'], 'auth_type' => $type, ); drupal_write_record('biblio_contributor_type', $ct_vals); } drupal_goto('admin/settings/biblio/types'); } function biblio_admin_types_hide() { $args = func_get_args(); if ($args[0] > 0 && is_numeric($args[0])) { $result = db_query('UPDATE {biblio_types} SET visible = 0 WHERE tid = %d ', $args[0]); } drupal_goto('admin/settings/biblio/types'); } function biblio_admin_types_show() { $args = func_get_args(); if ($args[0] > 0 && is_numeric($args[0])) { $result = db_query('UPDATE {biblio_types} SET visible = 1 WHERE tid = %d ', $args[0]); } drupal_goto('admin/settings/biblio/types'); } function biblio_admin_types_delete_form() { $args = func_get_args(); if ($args[1] > 0 && is_numeric($args[1])) { $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = %d ', $args[1]); $row = db_fetch_array($result); $num_rows = db_result(db_query('SELECT COUNT(*) FROM {biblio} as b WHERE b.biblio_type = %d', $row['tid'])); 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/settings/biblio/types', t('This action cannot be undone.'), t('Delete'), t('Cancel')); return $output; } else { drupal_goto('admin/settings/biblio/types'); } } function biblio_admin_types_delete_form_submit($form, & $form_state) { db_query('DELETE FROM {biblio_types} WHERE tid = %d', $form_state['values']['tid']); db_query('DELETE FROM {biblio_field_type} WHERE tid = %d', $form_state['values']['tid']); drupal_goto('admin/settings/biblio/types'); } 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/settings/biblio/types', t('By doing this, you will loose all customizations you have made to the field titles, this action cannot be undone!'), t('Do it!'), 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/settings/biblio/types"); } /* * This functin is used by both the admin/settings/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(& $form, $profile_user = false) { global $user; $allow_edit = variable_get('biblio_show_user_profile_form', '1'); $form['profile'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => ($profile_user) ? FALSE : TRUE, '#title' => ($profile_user) ? t('My publications') : t('Profile pages') ); if(!$profile_user){ $form['profile']['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['profile']['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 ? 0 : (($user->uid == 1) ? 0: 1), '#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['profile']['biblio_show_profile']['#default_value'] = (isset($profile_user->biblio_show_profile)) ? $profile_user->biblio_show_profile : variable_get('biblio_show_profile', '0'); } else { $form['profile']['biblio_show_profile']['#default_value'] = variable_get('biblio_show_profile', '0'); } $form['profile']['biblio_my_pubs_menu'] = array( '#type' => 'checkbox', '#title' => t('Show "My publications" item in the navigation menu'), '#disabled' => $allow_edit ? 0 : (($user->uid == 1) ? 0: 1), '#return_value' => 1, '#description' => '' ); if ($profile_user) { $form['profile']['biblio_my_pubs_menu']['#default_value'] = ((isset($profile_user->biblio_my_pubs_menu)) ? $profile_user->biblio_my_pubs_menu : variable_get('biblio_my_pubs_menu', '0')); } else { $form['profile']['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)'); while ($row = db_fetch_object($db_result)) { $options[$row->cid] = "$row->lastname, $row->firstname $row->initials "; } $form['profile']['biblio_contributor_id'] = array( '#type' => 'select', '#title' => t('Link My Profile with this Author from the Biblio database'), '#default_value' => $profile_user->biblio_contributor_id , '#options' => $options, '#description' => 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['profile']['biblio_lastname'] = array( '#type' => 'textfield', '#title' => t('My last name'), '#default_value' => $profile_user->biblio_lastname, '#disabled' => $allow_edit ? 0 : (($user->uid == 1) ? 0: 1), '#description' => t('This may be ueed to determine which publications are mine') ); */ } /* $form['profile']['biblio_profile_uid'] = array( '#type' => 'radios', '#title' => t('Select publications by'), '#default_value' => (isset($profile_user->biblio_profile_uid)) ? $profile_user->biblio_profile_uid : variable_get('biblio_profile_uid', 'lastname'), '#disabled' => $allow_edit ? 0 : (($user->uid == 1) ? 0: 1), '#options' => array( 'uid' => t('User ID'), 'lastname' => ($profile_user) ? t('My last name') : t('Last name'), 'uid_lastname' => t('Both (Last name & User ID)') ), '#description' => t('This defines the criteria used to select which publications will be listed on the users profile page') ); */} /* 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_admin_get_styles() { $styles = array(); $dir = drupal_get_path('module', 'biblio'); $files = array(); if ($dh = opendir($dir)) { while (($files[] = readdir($dh)) !== false) {} closedir($dh); foreach ($files as $file) { if (strstr($file, 'biblio_style_')) { //find the style files include_once $dir ."/". $file; if (function_exists(basename($file, ".inc") .'_info')) { $styles = array_merge($styles, call_user_func(basename($file, ".inc") .'_info')); //build and array of the short and long names } } } } return ($styles); } 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, COUNT(*) AS cnt FROM {biblio_contributor_data} GROUP BY lastname HAVING cnt>1'); 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'); break; } } function biblio_admin_author_types_form($form_state, $op = NULL, $id = NULL){ // var_dump($form_state, $op, $id); switch ($op){ case 'edit': $type = db_fetch_object(db_query("SELECT * FROM {biblio_contributor_type_data WHERE auth_type=%d",$id)); $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' =>$type->title, '#required' => true, '#maxlength' => 64 ); $form['hint'] = array( '#type' => 'textfield', '#title' => t('Description'), '#size' => 60, '#weight' => 2, '#default_value' => $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['#redirect'] = 'admin/settings/biblio/authors'; return $form; break; case 'delete': break; case 'hide': break; default: } } function theme_biblio_admin_author_types_form($form){ // print_r($form); $db_result = db_query("SELECT * FROM {biblio_contributor_type_data"); while ($row = db_fetch_object($db_result)) { $rows[] = array( $row->auth_type, $row->title, $row->hint, ($row->auth_type > 9) ? l(t('edit'), 'admin/settings/biblio/authors/edit/'. $row->auth_type) :'' , ); } $header = array( t('Type Id'), t('Contributor Type'), t('Description'), array('data' => t('Operations'),'colspan' => '2') ); $output = theme('table', $header, $rows); $output .= '
[ '. l(t('Add New Type'), 'admin/settings/biblio/authors/new') .' ]'; // $output .= ' [ '. l(t('Reset all types to defaults'), 'admin/settings/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_edit_form($form_state, $author_id){ $author = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_data} b WHERE b.cid = %d ', $author_id)); $form['#redirect'] = 'biblio/authors'; $form['cid'] = array( '#type' => 'value', '#value' => $author_id ); $form['drupal_uid'] = array( '#type' => 'textfield', '#title' => t('Drupal User ID'), '#default_value' => $author->drupal_uid, '#size' => 10, '#weight' => 12, '#required' => false, '#maxlength' => 128 ); $form['name'] = array( '#type' => 'textfield', '#title' => t('Complete Name'), '#default_value' => $author->name, '#size' => 100, '#weight' => 1, '#required' => true, '#maxlength' => 128 ); $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 ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save') ); return $form; } function biblio_admin_author_edit_form_validate($form, &$form_state) { if (!empty($form_state['values']['drupal_uid']) && (!is_numeric($form_state['values']['drupal_uid'])) ) { form_set_error('', t('The Drupal User ID must be an integer value')); } if (!empty($form_state['values']['drupal_uid']) && (is_numeric($form_state['values']['drupal_uid'])) && !user_load($form_state['values']['drupal_uid']) ) { form_set_error('', t('The Drupal User ID (@uid) does not exist',array('@uid' => $form_state['values']['drupal_uid']))); } foreach($form_state['values'] as $key => $value){ $form_state['values'][$key] = trim($value); } } function biblio_admin_author_edit_form_submit($form, &$form_state) { drupal_write_record('biblio_contributor_data', $form_state['values'], 'cid'); }