| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: station_catalog.pages.inc,v 1.2 2009/11/28 22:06:44 drewish Exp $ 3 4 /** 5 * @file 6 * 7 * This is the old catalog search code that I've replaced with views. I might 8 * want to revert to it so I'm keeping a copy of the D6 updated version. 9 */ 10 11 /* // Menu info 12 13 $items['station/catalog/search'] = array( 14 'title' => 'Catalog', 15 'page callback' => 'station_catalog_search_page', 16 'page arguments' => array('', ''), 17 'access arguments' => array('view catalog'), 18 'type' => MENU_NORMAL_ITEM, 19 ); 20 $items['station/catalog/search/%/%'] = array( 21 'title' => 'Catalog', 22 'page callback' => 'station_catalog_search_page', 23 'page arguments' => array(3, 4), 24 'access arguments' => array('view catalog'), 25 'type' => MENU_NORMAL_ITEM, 26 ); 27 */ 28 29 function station_catalog_search_page($field = '', $value ='') { 30 $perpage = 30; 31 32 $header = array( 33 'number' => array('data' => t('Number'), 'field' => 'sc.number'), 34 'artist' => array('data' => t('Artist'), 'field' => 'sc.artist'), 35 'album' => array('data' => t('Album'), 'field' => 'sc.album'), 36 'year' => array('data' => t('Year'), 'field' => 'sc.year'), 37 'label' => array('data' => t('Label'), 'field' => 'sc.label'), 38 ); 39 40 // Only search when there's a value and the field is valid. 41 if (!empty($value) && in_array($field, array('number', 'artist', 'album', 'year', 'label'), TRUE)) { 42 $header[$field]['sort'] = 'asc'; 43 $result = pager_query(db_rewrite_sql("SELECT n.nid, sc.* FROM {node} n INNER JOIN {station_catalog} sc ON n.nid = sc.nid WHERE LOWER(sc.$field) LIKE LOWER('%%%s%%')") . tablesort_sql($header), $perpage, 0, NULL, $value); 44 } 45 else { 46 $header['number']['sort'] = 'desc'; 47 $result = pager_query(db_rewrite_sql("SELECT n.nid, sc.* FROM {node} n INNER JOIN {station_catalog} sc ON n.nid = sc.nid") . tablesort_sql($header), $perpage, 0); 48 } 49 50 $rows = array(); 51 while ($item = db_fetch_object($result)) { 52 $link = 'node/'. $item->nid; 53 $rows[] = array( 54 array('data' => l($item->number, $link)), 55 array('data' => l($item->artist, $link)), 56 array('data' => l($item->album, $link)), 57 array('data' => $item->year ? $item->year : ''), 58 array('data' => $item->label) 59 ); 60 } 61 62 if (!$rows) { 63 $rows[] = array(array('colspan' => 4, 'data' => t('No matches were found.'))); 64 } 65 66 $output = '<div id="station-catalog-search">'; 67 $output .= drupal_get_form('station_catalog_search_form', $field, $value); 68 $output .= '<div id="station-catalog-search-results">'; 69 $output .= theme('pager', array(), $perpage); 70 $output .= theme('table', $header, $rows); 71 $output .= theme('pager', array(), $perpage); 72 $output .= '</div></div>'; 73 return $output; 74 } 75 76 function station_catalog_search_form($form_state, $field = '', $value ='') { 77 $form['search'] = array( 78 '#type' => 'fieldset', 79 '#title' => t('Search options'), 80 '#prefix' => '<div class="container-inline">', 81 '#suffix' => '</div>', 82 ); 83 $form['search']['field'] = array( 84 '#type' => 'select', 85 '#title' => t('Field'), 86 '#options' => array( 87 'artist' => t('Artist'), 88 'album' => t('Album'), 89 'label' => t('Label'), 90 'number' => t('Number'), 91 'year' => t('Year'), 92 ), 93 '#default_value' => $field, 94 ); 95 $form['search']['value'] = array( 96 '#type' => 'textfield', 97 '#title' => t('Value'), 98 '#default_value' => $value, 99 '#size' => 25, 100 ); 101 $form['search']['filter'] = array( 102 '#type' => 'submit', 103 '#value' => t('Filter'), 104 ); 105 if (!empty($value)) { 106 $form['search']['reset'] = array( 107 '#type' => 'submit', 108 '#value' => t('Reset'), 109 ); 110 } 111 return $form; 112 } 113 114 function station_catalog_search_form_submit($form, &$form_state) { 115 switch ($form_state['values']['op']) { 116 case t('Reset'): 117 $form_state['redirect'] = 'station/catalog/search/'; 118 119 case t('Filter'): 120 // Make sure it's an allowed search field. 121 if (in_array($form_state['values']['field'], array('number', 'artist', 'album', 'year', 'label'))) { 122 $form_state['redirect'] = 'station/catalog/search/'. $form_state['values']['field'] .'/'. $form_state['values']['value']; 123 } 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |