source: trunk/search.php @ 346

Last change on this file since 346 was 345, checked in by gweltas, 21 years ago

Merge of the 1.3.1 release
Creation of an unique include file (common.php)
Creation of an unique define file (include/constants.php)
Modification of the installation procedure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1<?php
2/***************************************************************************
3 *                                 search.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: search.php 345 2004-02-02 00:55:18Z gweltas $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20//----------------------------------------------------------- include
21$phpwg_root_path = './';
22include_once( $phpwg_root_path.'common.php' );
23//-------------------------------------------------- access authorization check
24check_login_authorization();
25//----------------------------------------------------------------- redirection
26$error = array();
27if ( isset( $_POST['search'] ) )
28{
29  $redirect = true;
30  $search = array();
31  $words = preg_split( '/\s+/', $_POST['search'] );
32  foreach ( $words as $i => $word ) {
33    if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
34    {
35      array_push( $search, $word );
36    }
37    else
38    {
39      $redirect = false;
40      array_push( $error, $lang['invalid_search'] );
41      break;
42    }
43  }
44  $search = array_unique( $search );
45  $search = implode( ',', $search );
46  if ( $redirect )
47  {
48    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
49    $url = add_session_id( $url, true );
50    header( 'Request-URI: '.$url );
51    header( 'Content-Location: '.$url ); 
52    header( 'Location: '.$url );
53    exit();
54  }
55}
56//----------------------------------------------------- template initialization
57//
58// Start output of page
59//
60$title= $lang['search_title'];
61include('include/page_header.php');
62
63$handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' );
64initialize_template();
65$tpl = array( 'search_title','search_return_main_page','submit',
66              'search_comments' );
67templatize_array( $tpl, 'lang', $handle );
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' );
89if (isset($_POST['search']))
90$vtp->setVar( $handle, 'text.value', $_POST['search'] );
91$vtp->closeSession( $handle, 'text' );
92$vtp->closeSession( $handle, 'line' );
93// mode of search : match all words or at least one of this words
94$vtp->addSession( $handle, 'line' );
95$vtp->addSession( $handle, 'group' );
96
97$vtp->addSession( $handle, 'radio' );
98$vtp->setVar( $handle, 'radio.name', 'mode' );
99$vtp->setVar( $handle, 'radio.value', 'OR' );
100$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
101if (!isset($_POST['mode']) || $_POST['mode'] == 'OR' )
102{
103  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
104}
105$vtp->closeSession( $handle, 'radio' );
106
107$vtp->addSession( $handle, 'radio' );
108$vtp->setVar( $handle, 'radio.name', 'mode' );
109$vtp->setVar( $handle, 'radio.value', 'AND' );
110$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
111if ( isset($_POST['mode']) && $_POST['mode'] == 'AND' )
112{
113  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
114}
115$vtp->closeSession( $handle, 'radio' );
116
117$vtp->closeSession( $handle, 'group' );
118$vtp->closeSession( $handle, 'line' );
119//---------------------------------------------------- return to main page link
120$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
121//----------------------------------------------------------- html code display
122$code = $vtp->Display( $handle, 0 );
123echo $code;
124//------------------------------------------------------------ log informations
125pwg_log( 'search', $title );
126mysql_close();
127include('include/page_tail.php');
128?>
Note: See TracBrowser for help on using the repository browser.