Changeset 17 for trunk/search.php


Ignore:
Timestamp:
May 25, 2003, 10:31:39 AM (21 years ago)
Author:
z0rglub
Message:

search improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/search.php

    r10 r17  
    2424if ( isset( $_POST['search'] ) )
    2525{
    26   $i = 0;
    27   if ( strlen( $_POST['search'] ) > 2 )
     26  $redirect = true;
     27  $search = array();
     28  $words = preg_split( '/\s+/', $_POST['search'] );
     29  foreach ( $words as $i => $word ) {
     30    if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
     31    {
     32      array_push( $search, $word );
     33    }
     34    else
     35    {
     36      $redirect = false;
     37      array_push( $error, $lang['invalid_search'] );
     38      break;
     39    }
     40  }
     41  $search = array_unique( $search );
     42  $search = implode( ',', $search );
     43  if ( $redirect )
    2844  {
    29     $url = add_session_id( 'category.php?cat=search&search='.
    30                            $_POST['search'], true );
     45    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
     46    $url = add_session_id( $url, true );
    3147    header( 'Request-URI: '.$url );
    3248    header( 'Content-Location: '.$url ); 
    3349    header( 'Location: '.$url );
    3450    exit();
    35   }
    36   else
    37   {
    38     $error[$i++] = $lang['invalid_search'];
    3951  }
    4052}
     
    6880  $vtp->closeSession( $handle, 'errors' );
    6981}
    70 //---------------------------------------------------------------- search field
     82//------------------------------------------------------------------------ form
     83// search field
    7184$vtp->addSession( $handle, 'line' );
    7285$vtp->setVar( $handle, 'line.name', $lang['search_field_search'] );
     
    7790$vtp->closeSession( $handle, 'text' );
    7891$vtp->closeSession( $handle, 'line' );
     92// mode of search : match all words or at least one of this words
     93$vtp->addSession( $handle, 'line' );
     94$vtp->addSession( $handle, 'group' );
     95
     96$vtp->addSession( $handle, 'radio' );
     97$vtp->setVar( $handle, 'radio.name', 'mode' );
     98$vtp->setVar( $handle, 'radio.value', 'OR' );
     99$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
     100if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
     101{
     102  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     103}
     104$vtp->closeSession( $handle, 'radio' );
     105
     106$vtp->addSession( $handle, 'radio' );
     107$vtp->setVar( $handle, 'radio.name', 'mode' );
     108$vtp->setVar( $handle, 'radio.value', 'AND' );
     109$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
     110if ( $_POST['mode'] == 'AND' )
     111{
     112  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     113}
     114$vtp->closeSession( $handle, 'radio' );
     115
     116$vtp->closeSession( $handle, 'group' );
     117$vtp->closeSession( $handle, 'line' );
    79118//---------------------------------------------------- return to main page link
    80119$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
     
    83122echo $code;
    84123//------------------------------------------------------------ log informations
     124pwg_log( 'category', $page['title'] );
     125mysql_close();
    85126$query = 'insert into '.PREFIX_TABLE.'history';
    86127$query.= '(date,login,IP,page) values';
Note: See TracChangeset for help on using the changeset viewer.