source: trunk/search.php @ 36

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

Deleting old code for history -> only using pwg_log

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 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/'.$user['template'].'/search.vtp' );
56initialize_template();
57
58$tpl = array( 'search_title','search_return_main_page','submit',
59              'search_comments' );
60templatize_array( $tpl, 'lang', $handle );
61//----------------------------------------------------------------- form action
62$vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) );
63//-------------------------------------------------------------- errors display
64if ( sizeof( $error ) != 0 )
65{
66  $vtp->addSession( $handle, 'errors' );
67  for ( $i = 0; $i < sizeof( $error ); $i++ )
68  {
69    $vtp->addSession( $handle, 'li' );
70    $vtp->setVar( $handle, 'li.li', $error[$i] );
71    $vtp->closeSession( $handle, 'li' );
72  }
73  $vtp->closeSession( $handle, 'errors' );
74}
75//------------------------------------------------------------------------ form
76// search field
77$vtp->addSession( $handle, 'line' );
78$vtp->setVar( $handle, 'line.name', $lang['search_field_search'].' *' );
79$vtp->addSession( $handle, 'text' );
80$vtp->setVar( $handle, 'text.size', '40' );
81$vtp->setVar( $handle, 'text.name', 'search' );
82$vtp->setVar( $handle, 'text.value', $_POST['search'] );
83$vtp->closeSession( $handle, 'text' );
84$vtp->closeSession( $handle, 'line' );
85// mode of search : match all words or at least one of this words
86$vtp->addSession( $handle, 'line' );
87$vtp->addSession( $handle, 'group' );
88
89$vtp->addSession( $handle, 'radio' );
90$vtp->setVar( $handle, 'radio.name', 'mode' );
91$vtp->setVar( $handle, 'radio.value', 'OR' );
92$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
93if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
94{
95  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
96}
97$vtp->closeSession( $handle, 'radio' );
98
99$vtp->addSession( $handle, 'radio' );
100$vtp->setVar( $handle, 'radio.name', 'mode' );
101$vtp->setVar( $handle, 'radio.value', 'AND' );
102$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
103if ( $_POST['mode'] == 'AND' )
104{
105  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
106}
107$vtp->closeSession( $handle, 'radio' );
108
109$vtp->closeSession( $handle, 'group' );
110$vtp->closeSession( $handle, 'line' );
111//---------------------------------------------------- return to main page link
112$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
113//----------------------------------------------------------- html code display
114$code = $vtp->Display( $handle, 0 );
115echo $code;
116//------------------------------------------------------------ log informations
117pwg_log( 'search', $page['title'] );
118mysql_close();
119?>
Note: See TracBrowser for help on using the repository browser.