source: trunk/search.php @ 17

Last change on this file since 17 was 17, checked in by z0rglub, 21 years ago

search improved

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1<?php
2/***************************************************************************
3 *                  search.php is a part of PhpWebGallery                  *
4 *                            -------------------                          *
5 *   last update          : Wednesday, July 25, 2002                       *
6 *   email                : pierrick@z0rglub.com                           *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation;                                         *
15 *                                                                         *
16 ***************************************************************************/
17
18//----------------------------------------------------------- personnal include
19include_once( './include/init.inc.php' );
20//-------------------------------------------------- access authorization check
21check_login_authorization();
22//----------------------------------------------------------------- redirection
23$error = array();
24if ( isset( $_POST['search'] ) )
25{
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 )
44  {
45    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
46    $url = add_session_id( $url, true );
47    header( 'Request-URI: '.$url );
48    header( 'Content-Location: '.$url ); 
49    header( 'Location: '.$url );
50    exit();
51  }
52}
53//----------------------------------------------------- template initialization
54$vtp = new VTemplate;
55$handle = $vtp->Open( './template/default/search.vtp' );
56// language
57$vtp->setGlobalVar( $handle, 'search_page_title',$lang['search_title'] );
58$vtp->setGlobalVar( $handle, 'search_title',     $lang['search_title'] );
59$vtp->setGlobalVar( $handle, 'search_return_main_page',
60                    $lang['search_return_main_page'] );
61$vtp->setGlobalVar( $handle, 'submit',           $lang['submit'] );
62// user
63$vtp->setGlobalVar( $handle, 'page_style',       $user['style'] );
64// structure
65$vtp->setGlobalVar( $handle, 'frame_start',      get_frame_start() );
66$vtp->setGlobalVar( $handle, 'frame_begin',      get_frame_begin() );
67$vtp->setGlobalVar( $handle, 'frame_end',        get_frame_end() );
68//----------------------------------------------------------------- form action
69$vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) );
70//-------------------------------------------------------------- errors display
71if ( sizeof( $error ) != 0 )
72{
73  $vtp->addSession( $handle, 'errors' );
74  for ( $i = 0; $i < sizeof( $error ); $i++ )
75  {
76    $vtp->addSession( $handle, 'li' );
77    $vtp->setVar( $handle, 'li.li', $error[$i] );
78    $vtp->closeSession( $handle, 'li' );
79  }
80  $vtp->closeSession( $handle, 'errors' );
81}
82//------------------------------------------------------------------------ form
83// search field
84$vtp->addSession( $handle, 'line' );
85$vtp->setVar( $handle, 'line.name', $lang['search_field_search'] );
86$vtp->addSession( $handle, 'text' );
87$vtp->setVar( $handle, 'text.size', '40' );
88$vtp->setVar( $handle, 'text.name', 'search' );
89$vtp->setVar( $handle, 'text.value', $_POST['search'] );
90$vtp->closeSession( $handle, 'text' );
91$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' );
118//---------------------------------------------------- return to main page link
119$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
120//----------------------------------------------------------- html code display
121$code = $vtp->Display( $handle, 0 );
122echo $code;
123//------------------------------------------------------------ log informations
124pwg_log( 'category', $page['title'] );
125mysql_close();
126$query = 'insert into '.PREFIX_TABLE.'history';
127$query.= '(date,login,IP,page) values';
128$query.= "('".time()."', '".$user['pseudo']."','".$_SERVER['REMOTE_ADDR']."'";
129$query.= ",'search');";
130@mysql_query( $query );
131?>
Note: See TracBrowser for help on using the repository browser.