You are here

function document_search_table in Document 6

Same name and namespace in other branches
  1. 7 document.inc \document_search_table()
  2. 8.x document.inc \document_search_table()
2 calls to document_search_table()
document_perform_search in ./document.inc
document_search_form in ./document.search.inc

File

./document.inc, line 142

Code

function document_search_table($sql) {

  //http://www.rahulsingla.com/projects/drupal-document-module#comment-194

  //During Ajax search, the path is document/search, and hence clicking table sort headers after a search

  //take you to a blank page with only the document table.

  //So, need to change the query to the document page.
  $q = $_GET['q'];
  $_GET['q'] = 'document';
  $headers = array(
    array(
      'data' => t('Type'),
      'field' => 'd.type',
      'class' => 'search-result-header col-type',
    ),
    array(
      'data' => t('Title'),
      'field' => 'title',
      'sort' => 'asc',
      'class' => 'search-result-header col-title',
    ),
    array(
      'data' => t('Author'),
      'field' => 'author',
      'class' => 'search-result-header col-author',
    ),
    array(
      'data' => t('Year of Publication'),
      'field' => 'publish_year',
      'class' => 'search-result-header col-publish-year',
    ),
    array(
      'data' => t('Keywords'),
      'class' => 'search-result-header col-keywords',
    ),
    array(
      'data' => '',
      'class' => 'search-result-header col-download',
    ),
  );

  //add the order by clause
  $sql .= tablesort_sql($headers);
  $results = pager_query($sql, 10);
  $moderate = user_access('moderate document');
  if ($moderate) {
    array_unshift($headers, '');
  }
  $imgUnpublish = theme_image(document_image_url('spacer.gif'), t('Unpublish'), t('Unpublish'), array(
    'onclick' => 'doc.changeDocStatus(this, %1$d, \'icon-unpublish\', false);',
    'class' => 'icon-unpublish',
    'width' => 16,
    'height' => 16,
  ), FALSE);
  $imgDelete = theme_image(document_image_url('spacer.gif'), t('Delete'), t('Delete'), array(
    'onclick' => 'doc.deleteDoc(this, %1$d, \'icon-delete\');',
    'class' => 'icon-delete',
    'width' => 16,
    'height' => 16,
  ), FALSE);
  $rows = array();
  while ($doc = db_fetch_object($results)) {
    $row = array(
      check_plain($doc->type),
      l($doc->title, 'node/' . $doc->nid),
      check_plain($doc->author),
      $doc->publish_year,
      check_plain($doc->keywords),
      l(t('Download'), $doc->url, array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    );
    if ($moderate) {
      array_unshift($row, sprintf($imgUnpublish . '   ' . $imgDelete, $doc->nid));
    }
    $rows[] = $row;
  }
  $table = theme('table', $headers, $rows);
  $table .= theme('pager', array(), 10, 0);

  //Restore the original query.
  $_GET['q'] = $q;
  return $table;
}