aboutsummaryrefslogtreecommitdiffstats
path: root/search.php
blob: 81d5d97f93cc36974c1d773305305be6b7517997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/***************************************************************************
 *                  search.php is a part of PhpWebGallery                  *
 *                            -------------------                          *
 *   last update          : Wednesday, July 25, 2002                       *
 *   email                : pierrick@z0rglub.com                           *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation;                                         *
 *                                                                         *
 ***************************************************************************/

//----------------------------------------------------------- personnal include
include_once( './include/init.inc.php' );
//-------------------------------------------------- access authorization check
check_login_authorization();
//----------------------------------------------------------------- redirection
$error = array();
if ( isset( $_POST['search'] ) )
{
  $redirect = true;
  $search = array();
  $words = preg_split( '/\s+/', $_POST['search'] );
  foreach ( $words as $i => $word ) {
    if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
    {
      array_push( $search, $word );
    }
    else
    {
      $redirect = false;
      array_push( $error, $lang['invalid_search'] );
      break;
    }
  }
  $search = array_unique( $search );
  $search = implode( ',', $search );
  if ( $redirect )
  {
    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
    $url = add_session_id( $url, true );
    header( 'Request-URI: '.$url );
    header( 'Content-Location: '.$url );  
    header( 'Location: '.$url );
    exit();
  }
}
//----------------------------------------------------- template initialization
$vtp = new VTemplate;
$handle = $vtp->Open( './template/default/search.vtp' );
// language
$vtp->setGlobalVar( $handle, 'search_page_title',$lang['search_title'] );
$vtp->setGlobalVar( $handle, 'search_title',     $lang['search_title'] );
$vtp->setGlobalVar( $handle, 'search_return_main_page',
                    $lang['search_return_main_page'] );
$vtp->setGlobalVar( $handle, 'submit',           $lang['submit'] );
// user
$vtp->setGlobalVar( $handle, 'page_style',       $user['style'] );
// structure
$vtp->setGlobalVar( $handle, 'frame_start',      get_frame_start() );
$vtp->setGlobalVar( $handle, 'frame_begin',      get_frame_begin() );
$vtp->setGlobalVar( $handle, 'frame_end',        get_frame_end() );
//----------------------------------------------------------------- form action
$vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) );
//-------------------------------------------------------------- errors display
if ( sizeof( $error ) != 0 )
{
  $vtp->addSession( $handle, 'errors' );
  for ( $i = 0; $i < sizeof( $error ); $i++ )
  {
    $vtp->addSession( $handle, 'li' );
    $vtp->setVar( $handle, 'li.li', $error[$i] );
    $vtp->closeSession( $handle, 'li' );
  }
  $vtp->closeSession( $handle, 'errors' );
}
//------------------------------------------------------------------------ form
// search field
$vtp->addSession( $handle, 'line' );
$vtp->setVar( $handle, 'line.name', $lang['search_field_search'] );
$vtp->addSession( $handle, 'text' );
$vtp->setVar( $handle, 'text.size', '40' );
$vtp->setVar( $handle, 'text.name', 'search' );
$vtp->setVar( $handle, 'text.value', $_POST['search'] );
$vtp->closeSession( $handle, 'text' );
$vtp->closeSession( $handle, 'line' );
// mode of search : match all words or at least one of this words
$vtp->addSession( $handle, 'line' );
$vtp->addSession( $handle, 'group' );

$vtp->addSession( $handle, 'radio' );
$vtp->setVar( $handle, 'radio.name', 'mode' );
$vtp->setVar( $handle, 'radio.value', 'OR' );
$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
{
  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
}
$vtp->closeSession( $handle, 'radio' );

$vtp->addSession( $handle, 'radio' );
$vtp->setVar( $handle, 'radio.name', 'mode' );
$vtp->setVar( $handle, 'radio.value', 'AND' );
$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
if ( $_POST['mode'] == 'AND' )
{
  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
}
$vtp->closeSession( $handle, 'radio' );

$vtp->closeSession( $handle, 'group' );
$vtp->closeSession( $handle, 'line' );
//---------------------------------------------------- return to main page link
$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
//----------------------------------------------------------- html code display
$code = $vtp->Display( $handle, 0 );
echo $code;
//------------------------------------------------------------ log informations
pwg_log( 'category', $page['title'] );
mysql_close();
$query = 'insert into '.PREFIX_TABLE.'history';
$query.= '(date,login,IP,page) values';
$query.= "('".time()."', '".$user['pseudo']."','".$_SERVER['REMOTE_ADDR']."'";
$query.= ",'search');";
@mysql_query( $query );
?>