uid "; } $sort_attrib = array("sort" => variable_get('biblio_sort', 'year'), 'order' => variable_get('biblio_order', 'DESC')); $limits = null; if (isset($_GET['order'])) { $sort_attrib['order'] = ($_GET['order'] == 'desc') ? 'desc' : 'asc'; } if (isset($_GET['sort'])) { $sort_attrib['sort'] = check_plain($_GET['sort']); } switch ($sort_attrib['sort']) { case 'type': $sortby = "ORDER BY bt.name %s, b.biblio_year DESC "; break; case 'title': //$sortby = "ORDER BY SUBSTRING(n.title,1,3) %s, b.biblio_year DESC "; $sortby = "ORDER BY $sort_title %s"; break; case 'author': $sortby = "ORDER BY bcd.lastname %s "; $where['bc-rank'] = "bc.rank=0"; $where['bc-auth-category'] = "bc.auth_category=1"; $joins['bc'] = ' INNER JOIN {biblio_contributor} as bc on b.vid = bc.vid '; $joins['bcd'] = ' JOIN {biblio_contributor_data} as bcd on bc.cid = bcd.cid '; break; case 'keyword': // added msh 070808 $sortby = "ORDER BY bkd.word %s "; $joins['bk'] = ' JOIN {biblio_keyword} as bk on b.vid = bk.vid '; $joins['bkd'] = ' JOIN {biblio_keyword_data} as bkd on bk.kid = bkd.kid '; $selects[] = "bkd.word as biblio_keyword"; $count_selects[] = "bkd.word"; break; case 'year': default: $sortby = "ORDER BY b.biblio_year %s, b.biblio_date %s"; } //end switch if (!isset($_SESSION['biblio_filter']) || !is_array($_SESSION['biblio_filter'])) { $_SESSION['biblio_filter'] = array(); } $session = &$_SESSION['biblio_filter']; if (!in_array('no_filters', $arg_list)) { foreach ($session as $filter) { $arg_list = array_merge($arg_list, $filter); } } if (count($arg_list) ) { $args = array(); while ($arg_list) { $type = $arg_list[0]; array_shift($arg_list); $operator = ($operator)?$operator:" AND "; //defaults to AND switch ($type) { case 'no_filters': break; case 'and': $operator = " AND "; break; case 'or': $operator = " OR "; break; case 'inline': $inline = true; break; case 'rss.xml': $rss_info['feed'] = true; break; case 'profile': $inline = "profile"; break; case 'cid': case 'aid': $bcc++; $term = explode("?",array_shift($arg_list)); $joins[] = "inner join {biblio_contributor} as bc". $bcc ." on n.vid = bc". $bcc .".vid"; $where[] = "bc". $bcc .".cid = '%d' "; $terms[] = db_escape_string($term[0]); array_push($args, $type, $term[0]); break; case 'term': case 'term_id': $term = explode("?",array_shift($arg_list)); $joins[] = "inner join {term_node} as tn on n.vid = tn.vid"; if ($type == 'term') { $joins[] = "inner join {term_data} as td on tn.tid= td.tid"; $where[] = "td.name = '%s' "; }elseif ($type == 'term_id') { $where[] = "tn.tid = '%d' "; } $terms[] = db_escape_string($term[0]); array_push($args, $type, $term[0]); break; case 'tg': $term = explode("?",array_shift($arg_list)); $where[] = "substring($sort_title,1 ,1)" . $match_op . " LOWER('%s')"; $terms[] = db_escape_string($term[0]); array_push($args, $type, $term[0]); $operator = NULL; break; case 'ag': //selects entries whoose authors firstname starts with the letter provided $term = explode("?",array_shift($arg_list)); $where[] = " UPPER(substring(bcd.lastname,1,1)) = '%s' "; $where['bc-rank'] = "bc.rank=0"; $joins['bc'] = ' INNER JOIN {biblio_contributor} as bc on b.vid = bc.vid '; $joins['bcd'] = ' JOIN {biblio_contributor_data} as bcd on bc.cid = bcd.cid '; $terms[] = db_escape_string(strtoupper($term[0])); array_push($args, $type, $term[0]); $operator = NULL; break; case 'author': $bcc++; $term = explode("?",array_shift($arg_list)); if (is_numeric($term[0])){ $joins[] = "inner join {biblio_contributor} as bc". $bcc ." on n.vid = bc". $bcc .".vid"; //$where[] = "bc". $bcc .".cid = '%d' "; // $cids = db_query('SELECT cid FROM {biblio_contributor_data} WHERE cid = %d OR aka = (SELECT aka FROM {biblio_contributor_data} WHERE cid = %d)' ,$term[0],$term[0]); while ($cid = db_fetch_object($cids) ){ $wr .= empty($wr)?'':' OR '; $wr .= "bc". $bcc .".cid = $cid->cid "; } $where[] = (!empty($wr)) ? $wr : "bc". $bcc .".cid = -1 "; // $where[] = 'bc'. $bcc .'.cid in ( (select cid from {biblio_contributor_data} // where cid = %d // or aka = %d // or cid = (select aka from {biblio_contributor_data} where cid = %d) // or aka = (select aka from {biblio_contributor_data} where cid = %d) // and biblio_contributor_data.aka > 0)) '; // $terms[] = db_escape_string($term[0]); // $terms[] = db_escape_string($term[0]); // $terms[] = db_escape_string($term[0]); // $terms[] = db_escape_string($term[0]); }else{ $where[] = " bcd". $bcc .'.name '. $match_op .' "[[:<:]]%s[[:>:]]" '; $joins[] = " JOIN {biblio_contributor} as bc". $bcc ." on b.vid = bc". $bcc .".vid "; $joins[] = " JOIN {biblio_contributor_data} as bcd". $bcc ." on bc". $bcc .".cid = bcd".$bcc .".cid "; $terms[] = db_escape_string($term[0]); $operator = NULL; $rss_info['title'] = t("Publications by " . $term[0]); $rss_info['description'] = t("These publications by %author are part of the works listed at %sitename", array('%author' => $term[0], '%sitename' => variable_get('site_name', 'Drupal'))); $rss_info['link'] = '/author/' . $term[0]; } array_push($args, $type, $term[0]); break; case 'publisher': $term = explode("?",array_shift($arg_list)); $where[] = "b.biblio_publisher ". $match_op ." '%s' "; $terms[] = db_escape_string($term[0]); array_push($args, $type, $term[0]); $operator = NULL; break; case 'year': $term = db_escape_string(array_shift($arg_list)); $where[] = "b.biblio_year=%d "; //$limit .= " AND b.biblio_year=%d "; $terms[] = (int)$term; array_push($args, $type, (int)$term); $operator = NULL; break; case 'uid': $term = db_escape_string(array_shift($arg_list)); $where[] = "n.uid=%d "; //$limit .= " AND b.biblio_year=%d "; $terms[] = (int)$term; array_push($args, $type, (int)$term); $operator = NULL; break; case 'keyword': $bkd++; $term = explode("?",array_shift($arg_list)); if (is_numeric($term[0])){ $terms[] = db_escape_string($term[0]); $joins[] = "inner join {biblio_keyword} as bk on n.vid = bk.vid"; //$joins[] = "inner join {biblio_keyword_data} as bkd on bk.kid= bkd.kid"; $where[] = "bk.kid = %d "; }else{ $where[] = " bkd". $bkd .'.word '. $match_op .' "[[:<:]]%s[[:>:]]" '; $joins[] = " JOIN {biblio_keyword} as bk". $bkd ." on b.vid = bk". $bkd .".vid "; $joins[] = " JOIN {biblio_keyword_data} as bkd". $bkd ." on bk". $bkd .".kid = bkd".$bkd .".kid "; $terms[] = db_escape_string($term[0]); $operator = NULL; $rss_info['title'] = t("Keyword " . $term[0]); $rss_info['description'] = t("These publications, containing the keyword: %keyword, are part of the works listed at %sitename", array('%keyword' => $term[0], '%sitename' => variable_get('site_name', 'Drupal'))); $rss_info['link'] = '/keyword/' . $term[0]; } array_push($args, $type, $term[0]); $operator = NULL; break; case 'citekey': $term = explode("?",array_shift($arg_list)); $terms[] = db_escape_string($term[0]); $where[] = "b.biblio_citekey= '%s' "; array_push($args, $type, $term[0]); $operator = NULL; break; case 'type': $term = db_escape_string(array_shift($arg_list)); $limit .= $operator. "b.biblio_type=%d "; $terms[] = (int)$term; array_push($args, $type, (int)$term); $operator = NULL; break; case 'order': $term = (db_escape_string(array_shift($arg_list)) == 'desc')?'desc':'asc'; $sort_attrib['order'] = $term; array_push($args, $type, $term); break; case 'sort': $term = db_escape_string(array_shift($arg_list)); $sort_attrib['sort'] = $term; array_push($args, $type, $term); switch ($term) { case 'type': $sortby = "ORDER BY bt.name %s, b.biblio_year DESC "; break; case 'title': $sortby = "ORDER BY $sort_title %s, b.biblio_year DESC "; break; case 'year': default: $sortby = "ORDER BY b.biblio_year %s, b.biblio_date %s, $sort_title ASC, bt.name ASC "; } //end switch break; case 'search': $term = explode("?",array_shift($arg_list)); $result_nids = split(',', $term[0]); $where[] = "n.nid in (".db_placeholders($result_nids).")"; foreach ($result_nids as $result_nid) { $terms[] = db_escape_string($result_nid); array_push($args, $type, $result_nid); } // Save search keyword to show in the filter list. $term = array_shift($arg_list); array_push($args, $type, $term); $operator = NULL; break; default: $fields = biblio_get_db_fields(); $term = explode("?",array_shift($arg_list)); if (in_array("biblio_$type",$fields)) { $where[] = "b.biblio_$type ".$match_op ." '%s' "; $terms[] = db_escape_string($term[0]); array_push($args, $type, $term[0]); $operator = NULL; } break; } } } $where[] = "n.type='biblio' "; if ($user->uid != 1 ) { $where[] = 'n.status = 1 '; }//show only published entries to everyone except admin $select = implode(', ', $selects); $count_select = implode(', ', $count_selects); $join = implode(' ', $joins); $where_clause = count($where) > 1 ? '('. implode(') AND (', $where) .')': $where[0]; $query = db_rewrite_sql("SELECT $select FROM {node} n $join WHERE $where_clause $limit $sortby "); $count_query = db_rewrite_sql("SELECT COUNT($count_select) FROM {node} n $join WHERE $where_clause $limit "); $_SESSION['last_biblio_query'] = $query; $terms[] = $sort_attrib['order']; // this is either asc or desc to be inserted into the first term of the ORDER clause if($sort_attrib['sort'] == 'year') $terms[] = $sort_attrib['order']; // we need any extra order term when sorting by year since there are to date terms biblio_year and biblio_date $_SESSION['last_biblio_query_terms'] = $terms; return (array('query' => $query, 'query_terms' => $terms, 'count_query' => $count_query, 'args' => $args, 'sort_attrib' => $sort_attrib, 'rss' => $rss_info )); } /** * biblio_show_results takes the query results from biblio_db_search and * adds some controls to the page then loops through the results applying * the selected style to each entry * * @param $result * @param $count * @param $attrib * @param $args * @param $inline * @return unknown_type */ function biblio_show_results($result, $attrib = array("sort" => 'year', 'order' => 'DESC'), $args = null,$inline=false) { global $pager_total_items; module_load_include('inc','biblio','biblio.contributors'); module_load_include('inc','biblio','biblio.keywords'); $base = variable_get('biblio_base', 'biblio'); $style = biblio_get_style(); if ($inline === 'profile') { $profile = true; $inline = false; } if (module_exists('popups')){ popups_add_popups(); } if (!$inline && !$profile) { if (variable_get('biblio_rss', 0)) { drupal_set_html_head(''); } // Search box. Has same permissions as the filter tab. $content .= '
'; if (variable_get('biblio_search',0) && user_access('show filter tab')) { $content .= drupal_get_form('biblio_search_form'); } if ( biblio_access('export')) { $content .= '
'.t('Export @count results', array('@count' => $pager_total_items[0])).':' . theme('biblio_export_links'). '
'; }else{ $content .= '
'.t('Found @count results', array('@count' => $pager_total_items[0])) .'

'; } // Add some links to the top of the page to change the sorting/ordering... if (user_access('show sort links')) { $content .= _biblio_sort_tabs($attrib, $options); } $content .= '
'; if (user_access('show filter tab')) { $content .= _biblio_filter_info_line($args); } } if ($inline === true) print '
'; if ($_GET['sort'] == 'title' || $_GET['sort'] == 'author') { if (strpos($_GET['q'],'ag') || strpos($_GET['q'],'tg')) { $value = substr($_GET['q'],strrpos($_GET['q'],'/')+1); } $content .= theme(biblio_alpha_line,$_GET['sort'],$value); } $count = 0; while ($node = db_fetch_object($result)) { $count++; $node->biblio_contributors = biblio_load_contributors($node->vid); $node->biblio_keywords = biblio_load_keywords($node->vid); if ( module_exists("upload") ) { $node->files = upload_load($node); } if (isset($node->biblio_year) && ($node->biblio_year == 9998)) $node->biblio_year = t("In Press") ; if (isset($node->biblio_year) && ($node->biblio_year == 9999)) $node->biblio_year = t("Submitted") ; // output separator bar if needed $content .= _biblio_category_separator_bar($attrib, $node); $inline_links = ($inline && variable_get('biblio_inlinemode_in_links',0)) ? true : false; $content .= theme('biblio_entry', $node,$base,$style,$inline); } //end while if ($count) $content .= '
'; $content .= theme('pager', 0, variable_get('biblio_rowsperpage', 25)); if ($count == 0) { $content .= "

".t("No items found")."

"; if (strstr($content, "Filters:")) { $content .= t('!modify_link or !remove_link your filters and try again.', array('!modify_link' => l(t('Modify'),"$base/filter"), '!remove_link' => l(t('remove'),"$base/filter/clear"))); } } if ($profile === true) return $content; if ($inline === true) return $content . ""; if ($inline === false) { $base_title = variable_get('biblio_base_title', 'Biblio'); drupal_set_title($base_title); print theme('page', $content); } } function _biblio_sort_tabs($attrib, $options) { $content = ''; $sort_links = array(); $tabs = variable_get('biblio_sort_tabs_style', 0); $order = ($attrib['order'] == "desc" || $attrib['order'] == "DESC")?"asc":"desc"; $cur_order = ($attrib['order'] == "desc" || $attrib['order'] == "DESC")?"desc":"asc"; $path = drupal_get_path('module','biblio'); $order_arrow = ($order == 'asc') ? ' ':' '; $sort_links = variable_get('biblio_sort_tabs', array('author'=>'author', 'title'=>'title', 'type'=>'type', 'year'=>'year', 'keyword'=>'keyword')); ksort($sort_links); $content .= $tabs ? '':''; return $content; } function _biblio_sort_tab($options, $title, $tabs = FALSE) { if ($tabs) { $content .= '
  • '; $content .= ''; $content .= ''. $title .$options['arrow'].'
  • '; } else { $content .= $options['pfx'].l($title ,$_GET['q'],$options['options']).$options['arrow'].$options['sfx']; } return $content; } function _biblio_filter_info_line($args) { $content = ''; $base = variable_get('biblio_base', 'biblio'); $session = &$_SESSION['biblio_filter']; // if there are any filters in place, print them at the top of the list if (count($args)) { $i = 0; while ($args) { $type = $args[0]; array_shift($args); $value = db_escape_string($args[0]); if ($type == 'search') { $search_content = ''. array_shift($args).''; continue; } if ($type == 'term_id') { $term = taxonomy_get_term($value); $value = $term->name; $type = t("Taxonomy Term"); } if ($type == 'keyword') { require_once(drupal_get_path('module', 'biblio') .'/biblio.keywords.inc'); if (is_numeric($value)) { $term = biblio_get_keyword_by_id($value); $value = $term->word; } $type = t("Keyword"); } if ($type == 'uid' ) { $user = user_load($value); $value = $user->name; $type = t("Drupal User"); } if ($type == 'aid' || ($type == 'author' && is_numeric($value))) { $author = biblio_get_contributor($value); $value = $author->name; $type = t("Author"); } if ($type == 'ag' ) { //return; $type = t("First letter of last name"); } if ($type == 'tg' ) { //return; $type = t("First letter of title"); } if ($type == 'type') { $pub_types = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid>0'); while ($option = db_fetch_object($pub_types)) { $pub_type["$option->tid"] = $option->name; } $value = $pub_type["$value"]; } array_shift($args); $params = array('%a' => $type , '%b' => $value ); $filtercontent .= ($i++ ? t(' and %a is %b', $params) : t('%a is %b', $params)) ; } if ($search_content) { $content .= '
    '.t('Search results for ').''; $content .= $search_content; if ($filtercontent) { $content .= '
    '.t('Filters').': '; } } else { $content .= '
    '.t('Filters').': '; } $content .= $filtercontent; $link_options = array(); if (isset($_GET['sort'])) { $link_options['query'] .= "sort=" . $_GET['sort']; } if (isset($_GET['order'])) { $link_options['query'] .= $link_options['query'] ? "&" : "" ; $link_options['query'] .= "order=" . $_GET['order']; } if ($search_content) { $content .= '  '.l('['.t('Reset Search').']',"$base/filter/clear", $link_options); } else { $content .= '  '.l('['.t('Clear All Filters').']',"$base/filter/clear", $link_options); } $content .= '
    '; } return $content; } function _biblio_category_separator_bar($attrib, $node) { static $_text = ''; switch ($attrib['sort']) { case 'title': $first = drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1); if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1) == '"' ) $first = drupal_ucfirst(drupal_substr(ltrim($node->title), 1, 1)); if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1) == "'" ) $first = drupal_ucfirst(drupal_substr(ltrim($node->title), 1, 1)); if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 2) == "A " ) $first = drupal_ucfirst(drupal_substr(ltrim($node->title), 2, 1)); if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 3) == "An " ) $first = drupal_ucfirst(drupal_substr(ltrim($node->title), 3, 1)); if (drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 4) == "The " ) $first = drupal_ucfirst(drupal_substr(ltrim($node->title), 4, 1)); if ( $first != $_text) { if ($_text != '' ) { $content .= theme_biblio_end_category_section(); } $_text = $first ; $content .= theme_biblio_separator_bar($_text); } break; case 'author': if ( (isset($node->biblio_contributors[1][0]['lastname'])) && (drupal_substr(drupal_ucfirst(ltrim($node->biblio_contributors[1][0]['lastname'])), 0, 1) != $_text)) { if ($_text != '' ) { $content .= theme_biblio_end_category_section(); } $_text = drupal_substr(drupal_ucfirst(ltrim($node->biblio_contributors[1][0]['lastname'])), 0, 1) ; $content .= theme_biblio_separator_bar($_text); } break; case 'type': if ($node->biblio_type_name != $_text) { if ($_text != '' ) { $content .= theme_biblio_end_category_section(); } $_text = $node->biblio_type_name; // $name = db_result(db_query("SELECT name FROM {biblio_types} as t where t.tid=%d", $node->biblio_type)) ; $content .= theme_biblio_separator_bar($_text); } break; case 'keyword': // added msh 08 aug 07 // $kw = array_shift($node->biblio_keyword); $tok = $node->biblio_keyword; if (empty($tok)) { $tok = t("No Keywords"); } if ($tok != $_text) { if ($_text != '' ) { $content .= theme_biblio_end_category_section(); } $_text = $tok; if ($_text != '') { $content .= theme_biblio_separator_bar($_text); } } break; case 'year': default: if ($node->biblio_year != $_text) { if ($_text != '' ) { $content .= theme_biblio_end_category_section(); } $_text = $node->biblio_year; $content .= theme_biblio_separator_bar($_text); } } //end switch return $content; } function theme_biblio_separator_bar($text) { $content .= "\n".'
    ' . $text . "
    \n"; $content .= "\n".'
    '; return $content; } function theme_biblio_end_category_section() { return "\n
    "; } /** * Add a search field on the main biblio page. */ /** * @param $form_state * @return unknown_type */ function biblio_search_form(&$form_state) { $form['biblio_search'] = array( '#prefix' => '', ); $form['biblio_search']['keys'] = array( '#type' => 'textfield', '#title' => '', '#default_value' => '', '#size' => 25, '#maxlength' => 255, ); $button_text = strlen(variable_get('biblio_search_button_text', ''))?variable_get('biblio_search_button_text', t('Biblio search')):t('Biblio search'); $form['biblio_search']['submit'] = array('#type' => 'submit', '#value' => $button_text); return $form; } /** * Build the query following the do_search algorithm in search.module. * Unfortunately we cannot reuse anything from do_search as everything * is hard-coded :-( * @param $keys */ function biblio_build_search_query($keys = '') { if ($keys != '') { $query = search_parse_query($keys); if ($query[2] == '') { form_set_error('keys', t('You must include at least one positive keyword with @count characters or more.', array('@count' => variable_get('minimum_word_size', 3)))); return FALSE; } if ($query === NULL || $query[0] == '') return FALSE; $where = '('.$query[2].')'; $args = $query[3]; if (!$query[5]) { $where .= " AND ($query[0])"; $args = array_merge($args, $query[1]); $join = " INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type"; } // The COUNT ensures that we get only nodes where "term1 AND term2" // match as we demand 2 matches. Note that this doesn't work when // using the partial word search patch. $args[] =$query[4]; $query = "SELECT distinct(i.sid) FROM {search_index} i INNER JOIN node n ON n.nid = i.sid $join WHERE n.status = 1 AND (n.type = 'biblio') AND $where AND i.type = 'node' GROUP BY i.type, i.sid HAVING COUNT(*) >= %d"; return db_query(db_rewrite_sql($query), $args); } return FALSE; } /** * When we submit a search, we revoke all current filters since search * and filtering are considered two different concepts things* conceptually. * * But we store the results as a filter (which is just a list of node ids that * matched the search request) so that we can reorder or export the search * results like with any other filter. The filter has three components: * ('search',,). * The second component, the filter value, is empty when submitting keywords. * In biblio_db_search we fill the second component with the list of nids * matching our keywords, as returned by node_search. We store the keywords * only for showing them in "Search results for ". */ /** * @param $form * @param $form_state * @return unknown_type */ function biblio_search_form_submit($form, &$form_state) { $keys = $form_state['values']['keys']; if ($keys != '') { $_SESSION['biblio_filter'] = array(array('search','',$keys)); $base = variable_get('biblio_base', 'biblio'); $form_state['redirect'] = $base; } else { // No keywords. Remove former search keys if any. Leaves other filters intact. if (_get_biblio_search_filter()){ $_SESSION['biblio_filter'] = array(); } } } /** * @param $arg * @return unknown_type */ function _get_biblio_search_filter($arg = 'keys') { if (variable_get('biblio_search',0) && is_array($_SESSION['biblio_filter']) && is_array($_SESSION['biblio_filter'][0]) && in_array('search',$_SESSION['biblio_filter'][0]) ){ switch ($arg) { case 'keys': return $_SESSION['biblio_filter'][0][2]; break; case 'nodelist': return $_SESSION['biblio_filter'][0][1]; break; } } } function _get_biblio_filters() { $fields = " b.biblio_year, t.name , t.tid "; $order = " b.biblio_year DESC"; $taxo_fields = "td.name as termname,td.tid as taxid, v.name as vocab_name"; $taxo_order = "vocab_name ASC, termname ASC"; $table = "{node} as n inner join {biblio} as b on n.vid=b.vid "; $join = "left join {biblio_types} as t on b.biblio_type = t.tid"; $taxo_join = array("inner join {term_node} as tn on n.vid = tn.vid", "left join {term_data} as td on tn.tid= td.tid", "left join {vocabulary} as v on v.vid= td.vid"); $taxo_joins = implode(' ',$taxo_join); $result = db_query("SELECT $fields FROM $table $join ORDER BY $order"); $authors = db_query("SELECT firstname, initials, lastname, cid FROM {biblio_contributor_data} ORDER BY lastname ASC"); $keywords = db_query("SELECT word, kid FROM {biblio_keyword_data} ORDER BY word ASC"); $taxoresult = db_query("SELECT $taxo_fields FROM $table $taxo_joins ORDER BY $taxo_order"); while ($option = db_fetch_object($result)) { if ($option->biblio_year == 9998) { $option->biblio_year = t("In Press"); } if ($option->biblio_year == 9999) { $option->biblio_year = t("Submitted"); } $pub_years["$option->biblio_year"] = $option->biblio_year; $pub_type["$option->tid"] = $option->name; } while($auth = db_fetch_object($authors)) { $pub_authors[$auth->cid] = $auth->lastname .((!empty($auth->firstname) || !empty($auth->initials))?', '.$auth->firstname.' '.$auth->initials :''); } while($keyword = db_fetch_object($keywords)) { $pub_keywords[$keyword->kid] = $keyword->word; } while ($tax = db_fetch_object($taxoresult)) { $pub_taxo["$tax->taxid"] = "$tax->vocab_name - $tax->termname"; } $author_select = isset($pub_authors) ? array('title' => t('Author'), 'options' => $pub_authors) : null; $years_select = isset($pub_years) ? array('title' => t('Year'), 'options' => array_unique($pub_years)) : null; $type_select = isset($pub_type) ? array('title' => t('Type'), 'options' => array_unique($pub_type)) : null; $tax_select = isset($pub_taxo) ? array('title' => t('Term'),'options' => array_unique($pub_taxo)) : null; $keyword_select = isset($pub_keywords) ? array('title' => t('Keyword'), 'options' => $pub_keywords) : null; $filters = array( 'author' => $author_select, 'type' => $type_select, 'term_id' => $tax_select, 'year' => $years_select, 'keyword' => $keyword_select, ); return $filters; } /** * @return unknown_type */ function biblio_form_filter() { // No longer use &$_SESSION so that we can alter $session in case of the search filter. $session = $_SESSION['biblio_filter']; $session = is_array($session) ? $session : array(); $filters = _get_biblio_filters(); $i = 0; $form['filters'] = array('#type' => 'fieldset', '#title' => t('Show only items where'), '#theme' => 'biblio_filters', ); foreach ($session as $filter) { list($type, $value) = $filter; // Don't show the search filter. Reset $session because of the $count(session) below. if ($type == 'search') { $session = array (); break; } if ($type == 'category') { // Load term name from DB rather than search and parse options array. $value = module_invoke('taxonomy', 'get_term', $value); $value = $value->name; }else { $value = $filters[$type]['options'][$value]; } $string = ($i++ ? 'and where %a is %b' : '%a is %b'); $form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $value))); } foreach ($filters as $key => $filter) { if (count ($filter['options'])) { $names[$key] = $filter['title']; $form['filters']['status'][$key] = array('#type' => 'select', '#options' => $filter['options']); } } $form['filters']['filter'] = array('#type' => 'radios', '#options' => $names, '#default_value' => 'author'); $form['filters']['buttons']['submit'] = array('#type' => 'submit', '#value' => (count($session) ? t('Refine') : t('Filter'))); if (count($session) && $type != 'search') { $form['filters']['buttons']['undo'] = array('#type' => 'submit', '#value' => t('Undo')); $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); } return $form; } /** * @param $form * @param $form_state * @return unknown_type */ function biblio_form_filter_submit($form, &$form_state) { // If the search filter was set, remove it now. if(_get_biblio_search_filter()){ $_SESSION['biblio_filter'] = array (); } $op = $form_state['values']['op']; $filters = _get_biblio_filters(); switch ($op) { case t('Filter'): case t('Refine'): if (isset($form_state['values']['filter'])) { $filter = $form_state['values']['filter']; // Flatten the options array to accommodate hierarchical/nested options. if (isset($filters[$filter]['options'])) { $flat_options = form_options_flatten($filters[$filter]['options']); } if (isset($flat_options[$form_state['values'][$filter]]) ) { $_SESSION['biblio_filter'][] = array($filter, $form_state['values'][$filter]); $base = variable_get('biblio_base', 'biblio'); drupal_goto($base); } } break; case t('Undo'): array_pop($_SESSION['biblio_filter']); break; case t('Reset'): $_SESSION['biblio_filter'] = array(); break; } } /** * @param $user * @param $profile * @return unknown_type */ function biblio_get_user_pubs($user, $profile='', $nofilters=''){ if (isset($user->biblio_contributor_id) && $user->biblio_contributor_id > 0 ){ $pubs = biblio_db_search('author', $user->biblio_contributor_id, $profile, $nofilters); }else{ $pubs = biblio_db_search('uid', $user->uid, $profile, $nofilters); } return $pubs; } /** * @param $node * @return unknown_type */ function biblio_view_inline(&$node) { $style = biblio_get_style(); $base = variable_get('biblio_base', 'biblio'); $layout = variable_get('biblio_node_layout', 'tabular'); $theme = ($layout == 'tabular') ? 'biblio_tabular' : 'biblio_long'; $output = '
    '; $output .= theme($theme, $node, $base, $style); $output .= '
    '; return $output; } /** * @return unknown_type */ function biblio_citekey_view() { $citekey = arg(2); $nid = db_fetch_object(db_query("SELECT nid FROM {biblio} WHERE biblio_citekey = '%s' ORDER BY vid DESC", $citekey)); if ($nid->nid > 0) { $node = node_load($nid->nid); return node_page_view($node); } else { return t("Sorry, citekey @cite not found", array('@cite'=>$citekey)); } } /** * @param $author * @param $aid * @param $base * @param $inline * @return unknown_type */ /** * @param $keywords * @param $base * @return unknown_type */ function _biblio_keyword_links($keywords,$base='biblio') { $options = array(); if (isset($_GET['sort'])) { $options['query'] .= "sort=" . $_GET['sort']; } if (isset($_GET['order'])) { $options['query'] .= $options['query'] ? "&" : ""; $options['query'] .= "order=" . $_GET['order']; } $html = ""; if (!is_array($keywords)) { $keywords = biblio_explode_keywords($keywords); } foreach($keywords as $kid => $keyword ) { $html .= (empty($html))? "" : "$sep "; $html .= l(trim($keyword), "$base/keyword/$kid" , $options); } return $html; } function biblio_author_page($filter = NULL) { $base = variable_get('biblio_base', 'biblio'); $menu = menu_get_active_title(); if ($menu == 'Authors') $path = $base.'/authors/'; if ($menu == 'Biblio settings') $path = 'admin/settings/biblio/author/list/'; if ($filter) { $filter = strtoupper($filter); $query_ext = " AND UPPER(SUBSTRING(lastname,1,1)) = '%s' "; $header_ext = t(' (whose last name starts with the letter "@letter") ',array('@letter' => $filter )); } else { $query_ext = NULL; $header_ext = NULL; } $db_result = db_query('SELECT bd.cid, bd.drupal_uid, bd.name, bd.lastname, bd.firstname, bd.prefix, bd.suffix, bd.initials, bd.affiliation, bd.md5, COUNT(*) AS cnt FROM {biblio_contributor} b, {biblio_contributor_data} bd WHERE bd.cid=b.cid '. $query_ext.' GROUP BY bd.cid, bd.drupal_uid, bd.name, bd.lastname, bd.firstname, bd.prefix, bd.suffix, bd.initials, bd.affiliation, bd.md5 HAVING COUNT(*) > 0 ORDER BY lastname ASC, SUBSTRING(firstname,1,1) ASC, initials ASC', $filter); while ($author = db_fetch_array($db_result)){ $authors[] = $author; } $rows[] = array(array('data' => theme(biblio_alpha_line, 'authors', $filter, $path), 'colspan' => 3)); for ($i=0; $i < count($authors); $i+=3) { $rows[] = array( array('data' => _biblio_format_author($authors[$i], $path) ), array('data' => isset($authors[$i+1])?_biblio_format_author($authors[$i+1], $path):'' ), array('data' => isset($authors[$i+2])?_biblio_format_author($authors[$i+2], $path):'' )); } //$header = array(array('data' => t('There are a total of @count authors !header_ext in the database',array('@count' => count($authors), '!header_ext' => $header_ext)), 'align' =>'center', 'colspan' => 3)); $output .= theme('table', $header, $rows); return $output; } /* * Helper function to format the authors and add edit links if required */ function _biblio_format_author($author, $path) { $style_name = biblio_get_style(); $style_function = "biblio_style_$style_name"."_author_options"; module_load_include('inc','biblio',"biblio_style_$style_name"); $author_options = $style_function(); $format = theme('biblio_format_authors', array($author), $author_options, $inline); $format .= ' ('. $author['cnt'] . ') '. ((biblio_access('edit_author'))?_biblio_author_edit_links($author, $path):''); return $format; } function _biblio_author_edit_links($author, $path) { $base = variable_get('biblio_base', 'biblio'); return l(' ['.t('edit').']', "$path" . $author['cid'] ."/edit/" ); } function biblio_keyword_page($filter = NULL) { if ($filter) { $filter = strtoupper($filter); $query_ext = " AND UPPER(SUBSTRING(word,1,1)) = '%s' "; $header_ext = t(' (which start with the letter "@letter") ',array('@letter' => $filter )); } else { $query_ext = NULL; $header_ext = NULL; } $db_result = db_query('SELECT bkd.kid, bkd.word, COUNT(*) AS cnt FROM {biblio_keyword} bk, {biblio_keyword_data} bkd WHERE bkd.kid=bk.kid '. $query_ext.' GROUP BY bkd.kid, bkd.word HAVING COUNT(*) > 0 ORDER BY word ASC', $filter); while ($keyword = db_fetch_object($db_result)){ $keywords[] = $keyword; } $rows[] = array(array('data' => theme(biblio_alpha_line, 'keywords', $filter), 'colspan' => 3)); for ($i=0; $i < count($keywords); $i+=3) { $rows[] = array( array('data' => _biblio_format_keyword($keywords[$i]) ), array('data' => isset($keywords[$i+1])?_biblio_format_keyword($keywords[$i+1]):'' ), array('data' => isset($keywords[$i+2])?_biblio_format_keyword($keywords[$i+2]):'' )); } //$header = array(array('data' => t('There are a total of @count keywords !header_ext in the database',array('@count' => count($keywords), '!header_ext' => $header_ext)), 'align' =>'center', 'colspan' => 3)); $output .= theme('table', $header, $rows); return $output; } function _biblio_format_keyword($keyword) { $base = variable_get('biblio_base', 'biblio'); $format = l(trim($keyword->word), "$base/keyword/$keyword->kid" ); $format .= ' ('. $keyword->cnt . ') ' ; $edit_link = ' ['.l(t('edit'), "$base/keyword/$keyword->kid/edit/" ).'] '; $format .= (user_access('administer biblio')) ? $edit_link: ''; return $format; }